Skip to content

多功能收款MPG

Cellvin Chung edited this page Feb 26, 2020 · 1 revision

版本:1.5

完成 config/initializers/newebpay.rb 中的 mpg_callback, notify_callback, payment_code_callback 設定

  • 若沒有設定 notify_callback,則只能使用即時交易支付方式(信用卡、WebATM、ezPay、Google Pay、Samsung Pay)
  • 若沒有設定 payment_code_callback,則付款資訊直接顯示在藍新金流頁面上,且使用者不會被導回至網站。

開始付款

# view
<%= newebpay_mpg_pay_button '顯示文字', payment_methods: [:credit_card, :vacc, :cvs, :barcode],
order_number: "訂單編號", description: "商品資訊", price: "金額", email: "email",
class: 'btn btn-success', id: 'payment', data: {disable_with: 'paying'} %>
參數 說明 必填 type 預設
order_number 商店訂單編號

限英、數、_,上限 30 字。
同商店中不可重複。
V String
description 商品資訊

上限 50 字。
V String
price 訂單金額 V Integer
email 付款人電子信箱 V String
payment_methods 付款方式

:credit 信用卡
:webatm WEB ATM
:vacc ATM 轉帳
:cvs 超商代碼
:barcode 超商條碼
:android_pay Google Pay
:samsung_pay Samsung Pay
:unionpay 銀聯卡
:p2g ezPay
:credit_red 信用卡紅利。
V Array of Symbols
inst_flag 信用卡分期付款

1 開啟所有分期期別
可開啟多種期別,以,分隔。如:3,6,12
可用期別:3, 6, 12, 18, 24, 30
String
login_required 藍新金流會員

true 需要登入藍新會員
false 不需登入藍新金流會員
Boolean false
merchant_id 商店代號 String config/initializers/newebpay.rb 中的 merchant_id
trade_limit 交易限制秒數

數字,60 ~ 900
Integer
expire_date 繳費有效期限

日期 Ymd,如 20150125
最多 180 天。
String 7 天
email_editable 是否可修改 Email

true 可修改
false 不可修改
Boolean false
comment 備註

上限 300 字
String
locale 語系

zh-twen
String zh-tw
cancel_url 取消支付返回網址 String
cvscom 物流

1 超商取貨不付款
2 超商取貨付款
3 超商取貨不付款及超商取貨付款

金額限 30 元 ~ 20,000 元。
String
  • 詳細說明參見原文件,部分參數名稱與預設值與原文件不同。
  • 原文件其他的必填欄位會自動產生,不需處理。
  • 原文件的 ReturnURL、NotifyURL、CustomerURL 已分別整合至config/initializers/newebpay.rb中的mpg_callbacknotify_callbackpayment_code_callback,不需再指定路徑。

在測試環境中

  • 信用卡與分期付款,卡號請填 4000-2211-1111-1111;紅利折抵請填 4003-5511-1111-1111,到期日及背面三碼任意填寫。
  • 銀聯卡不開放測試。
  • WebATM 將立刻完成交易並傳送交易完成資料。
  • ATM 轉帳、超商代碼、超商條碼可至測試後台點"模擬觸發"按鈕,會立刻傳送付款完成資料。
  • Google Pay 與 Samsung Pay 需使用綁定在裝置上的真實信用卡,但不會實際傳送資料至收單機構。
  • 物流可測試物流訂單收單與透過寄件管理介面列印寄件代碼,列印寄件單與實際包裹貨態改變,需在正式環境並實際進行包裹交寄。
  • ezPay 可測試是否直接扣除帳戶金額。

前景回傳

# config/initializers/newebpay.rb
config.mpg_callback do |newebpay_response|
   if newebpay_response.success?
     flash[:notice] = 'success'
     redirect_to root_path
   else
     Rails.logger.info "Newebpay Payment Not Succeed: #{newebpay_response.status}: #{newebpay_response.message} (#{newebpay_response.to_json})"
   end
 end
  • 付款是否成功:newebpay_response.success?
  • 建議在notify_callback處理資料,mpg_callback僅處理頁面redirect

背景回傳

# config/initializers/newebpay.rb
config.notify_callback do |newebpay_response|
   if newebpay_response.success?
     Order.find_by(order_number: newebpay_response.merchant_order_no)
          .update_attributes!(paid: true)
   else
     Rails.logger.info "Newebpay Payment Not Succeed: #{newebpay_response.status}: #{newebpay_response.message} (#{newebpay_response.to_json})"
   end
 end
  • 付款是否成功:newebpay_response.success?
  • 參見原文件第六點,可直接使用Result參數,原參數名稱underscore後為method
    • 例:newebpay_response.merchant_id, newebpay_response.trade_no

取號完成回傳

# config/initializers/newebpay.rb
config.payment_code_callback do |newebpay_response|
   if newebpay_response.success?
     Order.find_by(order_number: newebpay_response.merchant_order_no)
          .update_attributes!(paid: true)
   else
     Rails.logger.info "Newebpay Payment Not Succeed: #{newebpay_response.status}: #{newebpay_response.message} (#{newebpay_response.to_json})"
   end
 end
  • 取號是否成功:newebpay_response.success?
  • 參見原文件第七點
  • 說明同背景回傳