Skip to content

Commit

Permalink
增加ApplePay 付款方式及圓夢分期,30N 分期期數
Browse files Browse the repository at this point in the history
  • Loading branch information
AllennChang committed Jun 6, 2022
1 parent 629d2bd commit 31206d0
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 3 deletions.
84 changes: 84 additions & 0 deletions sample/sample_create_order_ApplePay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-

import importlib.util
spec = importlib.util.spec_from_file_location(
"ecpay_payment_sdk",
"/path/to/ecpay_payment_sdk.py"
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
from datetime import datetime

order_params = {
'MerchantTradeNo': datetime.now().strftime("NO%Y%m%d%H%M%S"),
'StoreID': '',
'MerchantTradeDate': datetime.now().strftime("%Y/%m/%d %H:%M:%S"),
'PaymentType': 'aio',
'TotalAmount': 2000,
'TradeDesc': '訂單測試',
'ItemName': '商品1#商品2',
'ReturnURL': 'https://www.ecpay.com.tw/return_url.php',
'ChoosePayment': 'ApplePay',
'ClientBackURL': 'https://www.ecpay.com.tw/client_back_url.php',
'ItemURL': 'https://www.ecpay.com.tw/item_url.php',
'Remark': '交易備註',
'ChooseSubPayment': '',
'OrderResultURL': 'https://www.ecpay.com.tw/order_result_url.php',
'NeedExtraPaidInfo': 'Y',
'DeviceSource': '',
'IgnorePayment': '',
'PlatformID': '',
'InvoiceMark': 'N',
'CustomField1': '',
'CustomField2': '',
'CustomField3': '',
'CustomField4': '',
'EncryptType': 1,
}

inv_params = {
# 'RelateNumber': 'Tea0001', # 特店自訂編號
# 'CustomerID': 'TEA_0000001', # 客戶編號
# 'CustomerIdentifier': '53348111', # 統一編號
# 'CustomerName': '客戶名稱',
# 'CustomerAddr': '客戶地址',
# 'CustomerPhone': '0912345678', # 客戶手機號碼
# 'CustomerEmail': '[email protected]',
# 'ClearanceMark': '2', # 通關方式
# 'TaxType': '1', # 課稅類別
# 'CarruerType': '', # 載具類別
# 'CarruerNum': '', # 載具編號
# 'Donation': '1', # 捐贈註記
# 'LoveCode': '168001', # 捐贈碼
# 'Print': '1',
# 'InvoiceItemName': '測試商品1|測試商品2',
# 'InvoiceItemCount': '2|3',
# 'InvoiceItemWord': '個|包',
# 'InvoiceItemPrice': '35|10',
# 'InvoiceItemTaxType': '1|1',
# 'InvoiceRemark': '測試商品1的說明|測試商品2的說明',
# 'DelayDay': '0', # 延遲天數
# 'InvType': '07', # 字軌類別
}

# 建立實體
ecpay_payment_sdk = module.ECPayPaymentSdk(
MerchantID='2000132',
HashKey='5294y06JbISpM5x9',
HashIV='v77hoKGq4kWxNNIS'
)

# 合併發票參數
order_params.update(inv_params)

try:
# 產生綠界訂單所需參數
final_order_params = ecpay_payment_sdk.create_order(order_params)

# 產生 html 的 form 格式
action_url = 'https://payment-stage.ecpay.com.tw/Cashier/AioCheckOut/V5' # 測試環境
# action_url = 'https://payment.ecpay.com.tw/Cashier/AioCheckOut/V5' # 正式環境
html = ecpay_payment_sdk.gen_html_post_form(action_url, final_order_params)
print(html)
except Exception as error:
print('An exception happened: ' + str(error))
3 changes: 2 additions & 1 deletion sample/sample_create_order_Credit_Installment.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
'MerchantMemberID': '',
}

# 分期付款:3,6,12,18,24 圓夢分期付款(TotalAmount須大於圓夢彈性分期最低交易金額):30N
extend_params_2 = {
'CreditInstallment': '3,6,12,18,24',
'CreditInstallment': '3,6,12,18,24' or '30N',
}

extend_params_3 = {
Expand Down
7 changes: 5 additions & 2 deletions sdk/ecpay_payment_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'ATM': 'ATM', # 自動櫃員機
'CVS': 'CVS', # 超商代碼
'BARCODE': 'BARCODE', # 超商條碼 (若為手機版時不支援)
'ApplePay': 'ApplePay', # ApplePay (僅支援Safari瀏覽器)
'ALL': 'ALL', # 不指定付款方式,由綠界顯示付款方式選擇頁面。
}

Expand Down Expand Up @@ -59,6 +60,7 @@
'BARCODE': 'BARCODE', # 超商條碼繳款
'Credit': 'Credit', # 信用卡 (MasterCard/JCB/VISA)
'GooglePay': 'GooglePay', # GooglePay
'ApplePay': '', # ApplePay
}

"""
Expand Down Expand Up @@ -93,6 +95,7 @@
'BARCODE_BARCODE': '超商條碼繳款',
'Credit_CreditCard': '信用卡',
'GooglePay': 'GooglePay',
'ApplePay': 'ApplePay',
}

"""
Expand Down Expand Up @@ -380,7 +383,7 @@ class CreateOrder(BasePayment):
"UnionPay": {'type': int, 'required': False, },
}

# 使用 ALL 或 Credit 付款方式: 分期付款(三擇一)
# 使用 ALL 或 Credit 付款方式: 分期付款、圓夢分期付款(三擇一)
__CREDIT_EXTEND_PARAMETERS_4 = {
"CreditInstallment": {'type': str, 'required': True, 'max': 20},
}
Expand Down Expand Up @@ -487,7 +490,7 @@ def create_order(self, client_parameters):
self.__CREDIT_EXTEND_PARAMETERS_3)
self.__check_pattern.append(self.__CREDIT_EXTEND_PARAMETERS_3)

# 使用 ALL 或 Credit 付款方式: 分期付款(三擇一)
# 使用 ALL 或 Credit 付款方式: 分期付款、圓夢分期付款(三擇一)
elif client_parameters.get('CreditInstallment'):
credit_extend_parameters = self.create_default_dict(
self.__CREDIT_EXTEND_PARAMETERS_4)
Expand Down

0 comments on commit 31206d0

Please sign in to comment.