-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
629d2bd
commit 31206d0
Showing
3 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters