|
@@ -0,0 +1,75 @@
|
|
|
+import requests
|
|
|
+import json
|
|
|
+import base64
|
|
|
+import hashlib
|
|
|
+import hmac
|
|
|
+import uuid
|
|
|
+
|
|
|
+# sandbox
|
|
|
+url = "https://sandbox-api-pay.line.me"
|
|
|
+# url_path = "/v3/payments/request"
|
|
|
+transactionId=2021101400692705810
|
|
|
+orderId=1
|
|
|
+url_path = "/v3/payments/" + str(transactionId) + "/confirm"
|
|
|
+
|
|
|
+# # production
|
|
|
+# url = "https://api-pay.line.me"
|
|
|
+ChannelId = 1656522171
|
|
|
+ChannelSecret = 'd6d37304bc39496025519366b9c0ab44'
|
|
|
+nonce = uuid.uuid4()
|
|
|
+
|
|
|
+def line_Signature(ChannelSecret, payload, nonce, url_path):
|
|
|
+ signature = hmac.new(
|
|
|
+ ChannelSecret.encode('utf-8'),
|
|
|
+ msg=(ChannelSecret + url_path + json.dumps(payload) + str(nonce)).encode('utf-8'),
|
|
|
+ digestmod=hashlib.sha256
|
|
|
+ ).digest()
|
|
|
+ return base64.b64encode(signature)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+# payload={
|
|
|
+# "amount": 100,
|
|
|
+# "currency": "TWD",
|
|
|
+# "orderId":1,
|
|
|
+# "packages" : [
|
|
|
+# {
|
|
|
+# "id" : "1",
|
|
|
+# "amount": 100,
|
|
|
+# "products" : [
|
|
|
+# {
|
|
|
+# "id" : "PEN-B-001",
|
|
|
+# "name" : "Pen Brown",
|
|
|
+# "imageUrl" : "https://pay-store.line.com/images/pen_brown.jpg",
|
|
|
+# "quantity" : 2,
|
|
|
+# "price" : 50
|
|
|
+# }
|
|
|
+# ]
|
|
|
+# }
|
|
|
+# ],
|
|
|
+# "redirectUrls" : {
|
|
|
+# "confirmUrl" : "https://pay-store.line.com/order/payment/confirm",
|
|
|
+# "cancelUrl" : "https://pay-store.line.com/order/payment/cancel"
|
|
|
+# }
|
|
|
+# }
|
|
|
+payload={
|
|
|
+ "amount": 100,
|
|
|
+ "currency": "TWD"
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+headers = {
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
+ 'X-LINE-ChannelId': str(ChannelId),
|
|
|
+ 'X-LINE-Authorization-Nonce': str(nonce),
|
|
|
+ 'X-LINE-Authorization': line_Signature(ChannelSecret, payload, nonce, url_path)
|
|
|
+}
|
|
|
+
|
|
|
+response = requests.request("POST", url + url_path, headers=headers, data=json.dumps(payload))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+print(response.text)
|