Hosted checkout
Create a payment session and connect checkout completion to your order.
Create a session
From your backend, call Create hosted payment using plugin-signed headers. Supply your merchant ID, order reference, amount and customer details. Currency defaults to INR. The return URL, callback URL, expiry and metadata are optional; see the labelled example below.
Redirect the customer
Store payment_id against your order and redirect the customer to checkout_url returned by ZytePe. Use the returned URL instead of constructing a payment URL yourself.
Confirm payment on the server
A browser return is not payment confirmation. Use the callback to update your backend and Hosted payment status for recovery or support checks. Its source example uses status paid; do not assume other APIs use the same casing or vocabulary.
Handle cancellations and refunds
Retain provider and transaction references for investigation. For a paid hosted payment, see the refund workflow. Confirm merchant/product enablement before using the flow with customers.
Request example
Choose Node.js, Python, PHP, Ruby, Java or cURL. Run signed requests on your backend. PHP, Ruby and Java include signing directly. Java requires JDK 17 or newer.
Signing helpers: Node.js · Python. cURL shows the request shape; generate its signature first.
import { pluginSignedHeaders } from './plugin-signing.mjs';
const path = `/payments/create`;
const query = '';
const payload = {
"merchant_id": "MERCHANT_001",
"order_id": "ORDER_123",
"amount": "499.00",
"currency": "INR",
"customer": {
"name": "Rahul Sharma",
"email": "rahul@example.com",
"phone": "9876543210"
},
"return_url": "https://store.example.com/zytepe/return",
"callback_url": "https://store.example.com/wp-json/zytepe/v1/webhook",
"expires_in_minutes": 1440,
"metadata": {
"platform": "woocommerce"
}
};
const body = JSON.stringify(payload);
const headers = pluginSignedHeaders({
method: 'POST', path, body,
keyId: process.env.ZYTEPE_API_KEY_ID,
secret: process.env.ZYTEPE_API_SECRET,
});
headers['Content-Type'] = 'application/json';
const url = 'https://api.zytepe.com' + path + (query ? '?' + query : '');
const response = await fetch(url, { method: 'POST', headers, body });
if (!response.ok) throw new Error('Request failed: HTTP ' + response.status);
const result = await response.json();
// Store the returned identifiers securely. Do not log customer data.import json, os
from urllib.parse import quote
from urllib.request import Request, urlopen
from zytepe_signing import plugin_signed_headers
path = f'/payments/create'
query = ''
payload = json.loads('''{
"merchant_id": "MERCHANT_001",
"order_id": "ORDER_123",
"amount": "499.00",
"currency": "INR",
"customer": {
"name": "Rahul Sharma",
"email": "rahul@example.com",
"phone": "9876543210"
},
"return_url": "https://store.example.com/zytepe/return",
"callback_url": "https://store.example.com/wp-json/zytepe/v1/webhook",
"expires_in_minutes": 1440,
"metadata": {
"platform": "woocommerce"
}
}''')
body = json.dumps(payload, separators=(',', ':'), ensure_ascii=False)
headers = plugin_signed_headers(
method='POST', path=path, body=body,
key_id=os.environ['ZYTEPE_API_KEY_ID'],
secret=os.environ['ZYTEPE_API_SECRET'],
)
headers['Content-Type'] = 'application/json'
url = 'https://api.zytepe.com' + path + ('?' + query if query else '')
request = Request(url, method='POST', headers=headers, data=body.encode('utf-8'))
with urlopen(request, timeout=30) as response:
result = json.load(response)
# Store identifiers securely; handle HTTPError/URLError in your application.<?php
// PHP 8+ with the cURL extension. Run on your server.
function envRequired(string $name): string {
$value = getenv($name);
if ($value === false || $value === '') throw new RuntimeException('Set ' . $name);
return $value;
}
$path = '/payments/create';
$query = '';
$body = <<<'JSON'
{
"merchant_id": "MERCHANT_001",
"order_id": "ORDER_123",
"amount": "499.00",
"currency": "INR",
"customer": {
"name": "Rahul Sharma",
"email": "rahul@example.com",
"phone": "9876543210"
},
"return_url": "https://store.example.com/zytepe/return",
"callback_url": "https://store.example.com/wp-json/zytepe/v1/webhook",
"expires_in_minutes": 1440,
"metadata": {
"platform": "woocommerce"
}
}
JSON;
$headers = [];
$key = envRequired('ZYTEPE_API_KEY_ID');
$secret = envRequired('ZYTEPE_API_SECRET');
$timestamp = (string) time();
$canonical = $timestamp . '.POST.' . $path . '.' . $body;
$signature = hash_hmac('sha256', $canonical, $secret);
$headers = ["X-ZytePe-Api-Key: $key", "X-ZytePe-Timestamp: $timestamp", "X-ZytePe-Signature: $signature"];
$headers[] = 'Content-Type: application/json';
$url = 'https://api.zytepe.com' . $path . ($query !== '' ? '?' . $query : '');
$ch = curl_init($url);
curl_setopt_array($ch, [CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => $headers,
CURLOPT_TIMEOUT => 30, CURLOPT_POSTFIELDS => $body]);
$response = curl_exec($ch);
if ($response === false) throw new RuntimeException(curl_error($ch));
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status >= 400) throw new RuntimeException('HTTP ' . $status);
$result = json_decode($response, true, 512, JSON_THROW_ON_ERROR);
// Store returned identifiers securely. Recover uncertain payments before retrying.require 'net/http'
require 'uri'
require 'json'
require 'openssl'
require 'securerandom'
path = '/payments/create'
query = ''
body = <<~'JSON'.chomp
{
"merchant_id": "MERCHANT_001",
"order_id": "ORDER_123",
"amount": "499.00",
"currency": "INR",
"customer": {
"name": "Rahul Sharma",
"email": "rahul@example.com",
"phone": "9876543210"
},
"return_url": "https://store.example.com/zytepe/return",
"callback_url": "https://store.example.com/wp-json/zytepe/v1/webhook",
"expires_in_minutes": 1440,
"metadata": {
"platform": "woocommerce"
}
}
JSON
headers = {}
key = ENV.fetch('ZYTEPE_API_KEY_ID')
secret = ENV.fetch('ZYTEPE_API_SECRET')
timestamp = Time.now.to_i.to_s
canonical = [timestamp, 'POST', path, body].join('.')
signature = OpenSSL::HMAC.hexdigest('SHA256', secret, canonical)
headers = { 'X-ZytePe-Api-Key' => key, 'X-ZytePe-Timestamp' => timestamp,
'X-ZytePe-Signature' => signature }
headers['Content-Type'] = 'application/json'
uri = URI('https://api.zytepe.com' + path + (query.empty? ? '' : '?' + query))
request = Net::HTTP::Post.new(uri, headers)
request.body = body
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, open_timeout: 10, read_timeout: 30) do |http|
http.request(request)
end
raise 'HTTP ' + response.code unless response.is_a?(Net::HTTPSuccess)
result = JSON.parse(response.body)
# Store returned identifiers securely. Recover uncertain payments before retrying.// Java 17+. Save as ZytePeExample.java and run on your server.
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.*;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
import java.security.MessageDigest;
import java.util.HexFormat;
import java.util.UUID;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
public class ZytePeExample {
private static String env(String name) {
String value = System.getenv(name);
if (value == null || value.isBlank()) throw new IllegalArgumentException("Set " + name);
return value;
}
public static void main(String[] args) throws Exception {
String path = "/payments/create";
String query = "";
String body = """
{
"merchant_id": "MERCHANT_001",
"order_id": "ORDER_123",
"amount": "499.00",
"currency": "INR",
"customer": {
"name": "Rahul Sharma",
"email": "rahul@example.com",
"phone": "9876543210"
},
"return_url": "https://store.example.com/zytepe/return",
"callback_url": "https://store.example.com/wp-json/zytepe/v1/webhook",
"expires_in_minutes": 1440,
"metadata": {
"platform": "woocommerce"
}
}
""".stripTrailing();
var request = HttpRequest.newBuilder(URI.create(
"https://api.zytepe.com" + path + (query.isEmpty() ? "" : "?" + query)))
.timeout(Duration.ofSeconds(30));
String key = env("ZYTEPE_API_KEY_ID");
String secret = env("ZYTEPE_API_SECRET");
String timestamp = Long.toString(Instant.now().getEpochSecond());
String canonical = timestamp + ".POST." + path + "." + body;
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
String signature = HexFormat.of().formatHex(mac.doFinal(canonical.getBytes(StandardCharsets.UTF_8)));
request.header("X-ZytePe-Api-Key", key).header("X-ZytePe-Timestamp", timestamp)
.header("X-ZytePe-Signature", signature);
request.header("Content-Type", "application/json");
request.method("POST", HttpRequest.BodyPublishers.ofString(body, StandardCharsets.UTF_8));
var client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build();
var response = client.send(request.build(), HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
if (response.statusCode() < 200 || response.statusCode() >= 300)
throw new IllegalStateException("HTTP " + response.statusCode());
String result = response.body(); // Parse JSON using your application's JSON library.
// Store identifiers securely. Recover uncertain payments before retrying.
}
}curl --request POST \
--url 'https://api.zytepe.com/payments/create' \
--header 'X-ZytePe-Api-Key: <key-id>' \
--header 'X-ZytePe-Timestamp: <unix-seconds>' \
--header 'X-ZytePe-Signature: <signature>' \
--header 'Content-Type: application/json' \
--data-binary @request.jsonRequest fields
Optional fields can be omitted. Conditional fields depend on the payment method. Labels reflect the reviewed API schemas and handler checks.
merchant_idRequiredYour merchant identifier.
order_idRequiredYour order reference.
amountRequiredPayment amount in the documented currency.
customerRequiredCustomer identity details.
customer.nameRequiredRequired customer detail.
customer.emailRequiredRequired customer detail.
customer.phoneRequiredRequired customer detail.
currencyOptionalDefaults to INR.
return_urlOptionalCustomer return destination. A return is not payment confirmation.
callback_urlOptionalPayment callback destination.
expires_in_minutesOptionalDefaults to 1440 minutes.
metadataOptionalAdditional order context.
Request body
{
"merchant_id": "MERCHANT_001",
"order_id": "ORDER_123",
"amount": "499.00",
"currency": "INR",
"customer": {
"name": "Rahul Sharma",
"email": "rahul@example.com",
"phone": "9876543210"
},
"return_url": "https://store.example.com/zytepe/return",
"callback_url": "https://store.example.com/wp-json/zytepe/v1/webhook",
"expires_in_minutes": 1440,
"metadata": {
"platform": "woocommerce"
}
}Example response
{
"payment_id": "pay_123",
"checkout_url": "https://pay.zytepe.com/pay_123",
"status": "created",
"order_id": "ORDER_123",
"amount": "499.0000",
"currency": "INR"
}Explore the business workflow: Payment gateway overview.
