|
@@ -38,14 +38,22 @@ def ecpay_payment(
|
|
owner_id=current_user.id,
|
|
owner_id=current_user.id,
|
|
epayment='ecpay',
|
|
epayment='ecpay',
|
|
remark=remark_string)
|
|
remark=remark_string)
|
|
|
|
+ items = payment_data.item
|
|
|
|
+ items = items.split("#")
|
|
|
|
+ print(payment.item)
|
|
|
|
+ content = {}
|
|
|
|
+ for item in items:
|
|
|
|
+ pair = item.split()
|
|
|
|
+ content[str(pair[0]).lower()] = pair[1]
|
|
|
|
+ content_string = json.dumps(content, ensure_ascii=False).replace('"', "'")
|
|
order_params = {
|
|
order_params = {
|
|
'MerchantTradeNo': MerchantTradeNo,
|
|
'MerchantTradeNo': MerchantTradeNo,
|
|
'StoreID': 'SaaS',
|
|
'StoreID': 'SaaS',
|
|
'MerchantTradeDate': datetime.now().strftime("%Y/%m/%d %H:%M:%S"),
|
|
'MerchantTradeDate': datetime.now().strftime("%Y/%m/%d %H:%M:%S"),
|
|
'PaymentType': 'aio',
|
|
'PaymentType': 'aio',
|
|
- 'TotalAmount': payment.amount,
|
|
|
|
|
|
+ 'TotalAmount': payment_data.amount,
|
|
'TradeDesc': 'SaaS訂單',
|
|
'TradeDesc': 'SaaS訂單',
|
|
- 'ItemName': f'credit: {payment.item}',
|
|
|
|
|
|
+ 'ItemName': payment_data.item,
|
|
'ReturnURL': 'https://cloud.choozmo.com/api/v1/payment/ecpay-result-return',
|
|
'ReturnURL': 'https://cloud.choozmo.com/api/v1/payment/ecpay-result-return',
|
|
'ChoosePayment': 'ALL',
|
|
'ChoosePayment': 'ALL',
|
|
'ClientBackURL': 'https://cloud.choozmo.com/payment',
|
|
'ClientBackURL': 'https://cloud.choozmo.com/payment',
|
|
@@ -58,14 +66,14 @@ def ecpay_payment(
|
|
'IgnorePayment': 'ATM#CVS#BARCODE',
|
|
'IgnorePayment': 'ATM#CVS#BARCODE',
|
|
'PlatformID': '',
|
|
'PlatformID': '',
|
|
'InvoiceMark': 'N',
|
|
'InvoiceMark': 'N',
|
|
- 'CustomField1': f'user id: {str(current_user.id)}',
|
|
|
|
- 'CustomField2': f'pyment id: {str(payment.id)}',
|
|
|
|
- 'CustomField3': '',
|
|
|
|
|
|
+ 'CustomField1': f'{str(payment.id)}',
|
|
|
|
+ 'CustomField2': f'{str(current_user.id)}',
|
|
|
|
+ 'CustomField3': content_string,
|
|
'CustomField4': '',
|
|
'CustomField4': '',
|
|
'EncryptType': 1,
|
|
'EncryptType': 1,
|
|
'Language': lang,
|
|
'Language': lang,
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ print(order_params)
|
|
extend_params_1 = {
|
|
extend_params_1 = {
|
|
'ExpireDate': 7,
|
|
'ExpireDate': 7,
|
|
'PaymentInfoURL': 'https://www.ecpay.com.tw/payment_info_url.php',
|
|
'PaymentInfoURL': 'https://www.ecpay.com.tw/payment_info_url.php',
|
|
@@ -144,7 +152,7 @@ def ecpay_payment(
|
|
return html
|
|
return html
|
|
except Exception as error:
|
|
except Exception as error:
|
|
print('An exception happened: ' + str(error))
|
|
print('An exception happened: ' + str(error))
|
|
-
|
|
|
|
|
|
+
|
|
@router.post('/ecpay-payment')
|
|
@router.post('/ecpay-payment')
|
|
def ecpay_payment(
|
|
def ecpay_payment(
|
|
*,
|
|
*,
|
|
@@ -164,18 +172,25 @@ def ecpay_payment(
|
|
owner_id=current_user.id,
|
|
owner_id=current_user.id,
|
|
epayment='ecpay',
|
|
epayment='ecpay',
|
|
remark=remark_string)
|
|
remark=remark_string)
|
|
|
|
+ items = payment_data.item
|
|
|
|
+ items = items.split("#")
|
|
|
|
+ content = {}
|
|
|
|
+ for item in items:
|
|
|
|
+ pair = item.split()
|
|
|
|
+ content[str(pair[0]).lower()] = pair[1]
|
|
|
|
+ content_string = json.dumps(content, ensure_ascii=False)
|
|
order_params = {
|
|
order_params = {
|
|
'MerchantTradeNo': MerchantTradeNo,
|
|
'MerchantTradeNo': MerchantTradeNo,
|
|
'StoreID': 'SaaS',
|
|
'StoreID': 'SaaS',
|
|
'MerchantTradeDate': datetime.now().strftime("%Y/%m/%d %H:%M:%S"),
|
|
'MerchantTradeDate': datetime.now().strftime("%Y/%m/%d %H:%M:%S"),
|
|
'PaymentType': 'aio',
|
|
'PaymentType': 'aio',
|
|
- 'TotalAmount': payment.amount,
|
|
|
|
|
|
+ 'TotalAmount': payment_data.amount,
|
|
'TradeDesc': 'SaaS訂單',
|
|
'TradeDesc': 'SaaS訂單',
|
|
- 'ItemName': f'credit: {payment.item}',
|
|
|
|
|
|
+ 'ItemName': payment_data.item,
|
|
'ReturnURL': 'https://cloud.choozmo.com/api/v1/payment/ecpay-result-return',
|
|
'ReturnURL': 'https://cloud.choozmo.com/api/v1/payment/ecpay-result-return',
|
|
'ChoosePayment': 'ALL',
|
|
'ChoosePayment': 'ALL',
|
|
- 'ClientBackURL': 'https://cloud.choozmo.com/payment',
|
|
|
|
- 'ItemURL': 'https://cloud.choozmo.com/payment',
|
|
|
|
|
|
+ 'ClientBackURL': 'https://cloud.choozmo.com/main/admin/test-payment',
|
|
|
|
+ 'ItemURL': 'https://cloud.choozmo.com/main/admin/test-payment',
|
|
'Remark': '',
|
|
'Remark': '',
|
|
'ChooseSubPayment': '',
|
|
'ChooseSubPayment': '',
|
|
'OrderResultURL': '',
|
|
'OrderResultURL': '',
|
|
@@ -184,9 +199,9 @@ def ecpay_payment(
|
|
'IgnorePayment': 'ATM#CVS#BARCODE',
|
|
'IgnorePayment': 'ATM#CVS#BARCODE',
|
|
'PlatformID': '',
|
|
'PlatformID': '',
|
|
'InvoiceMark': 'N',
|
|
'InvoiceMark': 'N',
|
|
- 'CustomField1': f'user id: {str(current_user.id)}',
|
|
|
|
- 'CustomField2': f'pyment id: {str(payment.id)}',
|
|
|
|
- 'CustomField3': '',
|
|
|
|
|
|
+ 'CustomField1': str(payment.id),
|
|
|
|
+ 'CustomField2': str(current_user.id),
|
|
|
|
+ 'CustomField3': content_string,
|
|
'CustomField4': '',
|
|
'CustomField4': '',
|
|
'EncryptType': 1,
|
|
'EncryptType': 1,
|
|
'Language': lang,
|
|
'Language': lang,
|
|
@@ -324,9 +339,15 @@ CheckMacValue: {CheckMacValue}\
|
|
")
|
|
")
|
|
|
|
|
|
if RtnCode==1:
|
|
if RtnCode==1:
|
|
- ytviews_id = int(CustomField1)
|
|
|
|
- ytviews = crud.ytviews.get(db=db, id=ytviews_id)
|
|
|
|
- remark = json.loads(ytviews.remark)
|
|
|
|
|
|
+ payment_id = int(CustomField1)
|
|
|
|
+ payment = crud.ytviews.get(db=db, id=payment_id)
|
|
|
|
+ remark = json.loads(payment.remark)
|
|
remark['TradeNo'] = TradeNo
|
|
remark['TradeNo'] = TradeNo
|
|
- crud.ytviews.update(db, db_obj=ytviews, obj_in={"payment_state":"succeeded", "remark":json.dumps(remark, ensure_ascii=False)})
|
|
|
|
|
|
+ content_string = CustomField3.replace("'",'"')
|
|
|
|
+ content:dict = json.loads(content_string)
|
|
|
|
+ if 'credit' in content.keys:
|
|
|
|
+ add_credit = content['credit']
|
|
|
|
+ if user := crud.user.get(id=int(CustomField2)):
|
|
|
|
+ user.update(db, db_obj=payment, obj_in={"available_time": user.available_tiem + int(add_credit)})
|
|
|
|
+ crud.payment.update(db, db_obj=payment, obj_in={"payment_state":"succeeded", "remark":json.dumps(remark, ensure_ascii=False)})
|
|
return Response(content='1', status_code=status.HTTP_200_OK)
|
|
return Response(content='1', status_code=status.HTTP_200_OK)
|