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"))api_key = 'DjlHuWlApznJ7vrhPBL0fA'
api_secret = '3pPl6TbsoRlz0FLpKM6r-UG788g4-Fk5d1v1gKdXAA8'
string_to_signature = {"merchant_id": "UuOLMTDbSII57Dfu"}
digest = OpenSSL::Digest.new('sha512')
signature = OpenSSL::HMAC.digest(digest, api_secret, string_to_signature)<?php
namespace Kriptopay;
class Authentication
{
private $apiKey;
private $apiSecret;
public function __construct($apiKey, $apiSecret) {
$this->apiKey = $apiKey;
$this->apiSecret= $apiSecret;
}
public function buildRequestHeaders($method, $path, $body, $headers) {
$bodyHash = json_encode($body, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$signature = hash_hmac('sha512', $bodyHash, $this->apiSecret);
return [
'HMAC' => $signature,
'Authorization' => $this->apiKey
];
}
}Last updated