Code samples
import requests
import json
import hmac
import hashlib
from wsgiref.handlers import format_date_time
from datetime import datetime
from time import mktime
# Api keys
api_key = "your_API_key"
api_secret = "your_API_secret"
merchant_id = "your_merchant_id"
payment_page_id = "your_payment_page_id"
# Content type
content_type = "application/json"
# Date
payment_date = format_date_time(mktime(datetime.now().timetuple()))
# [Kriptopay] Create payment
def create_invoice_payment_kriptopaycom(transaction_id, customer_id):
if price_amount and price_currency and pay_currency:
payment_host = "https://kriptopay.com"
payment_path = "/api/merchant/invoice"
payment_url = payment_host + payment_path
payment_data = {
"merchant_id": merchant_id,
"transaction_id": transaction_id,
"identifier": customer_id,
"payment_page": payment_page_id
}
body = json.dumps(payment_data, separators=(',', ':'), sort_keys=False)
signature = hmac.new(str.encode(api_secret), body.encode(), hashlib.sha512).hexdigest()
authorization = api_key
headers = {
"HMAC": signature,
"Authorization": authorization,
"Content-Type": content_type,
"Date": payment_date,
}
# Log (Request headers)
f = open("request-log.json", "w")
f.write(json.dumps(headers))
f.write("\n")
f.write(body)
f.close()
# Request post
response = requests.post(payment_url, headers=headers, data=body)
# Log (Response)
# Log (Request headers)
f = open("response.json", "w")
f.write(response.text)
f.close()
if response.status_code == 201:
response_data = json.loads(response.text)
payment_redirect_url = response_data["data"]["url"]
return payment_redirect_url
else:
return None
else:
return None
print(create_invoice_payment_kriptopaycom("custom_transaction_id", "user_id"))Last updated