Search by

Official PHP SDK for the GardeshPay Merchant API.

v0.1.1 2026-12-01 08:46 UTC

This package is auto-updated.

Last update: 2026-12-01 09:11:30 UTC


README

Official PHP client for the GardeshPay Merchant API.

composer require gardeshpay/sdk

Use this library only on your server. Keep API credentials in environment variables or a secrets manager.

Install

Requires PHP 8.1+ with the curl, json, and hash extensions.

composer require gardeshpay/sdk

Quick start

<?php

require __DIR__ . '/vendor/autoload.php';

use GardeshPay\GardeshPay;

$gp = new GardeshPay([
    'apiKey' => getenv('GARDESHPAY_API_KEY'),
    'hmacSecret' => getenv('GARDESHPAY_HMAC_SECRET'),
    'baseUrl' => getenv('GARDESHPAY_BASE_URL'), // e.g. https://api.example.com/v1
]);

$payment = $gp->createPayment([
    'orderRef' => 'ORD-1001',
    'amountRial' => 250_000,
    'returnUrl' => 'https://shop.example.com/return',
    'description' => 'Order 1001',
    'customerMobile' => '09121234567',
    'customerFullName' => 'Mina Karimi',
]);

header('Location: ' . ($payment['startPayUrl'] ?? $payment['checkoutUrl']));

// After the buyer returns to returnUrl:
$verified = $gp->verifyPayment($payment['paymentId']);
if (($verified['status'] ?? '') === 'SUCCEEDED') {
    // fulfill the order
}

API

Method Description
createPayment(array $input) Create a payment and receive redirect URLs
getPayment(string $paymentId) Read payment status
verifyPayment(string $paymentId) Confirm payment before fulfillment
createRefund(array $input) Refund a succeeded payment
Webhook::verify(...) Validate an inbound webhook signature

createPayment

Field Required Description
orderRef yes Your order reference
amountRial yes Amount in Iranian Rials (integer)
returnUrl yes HTTPS URL where the buyer returns after payment
callbackUrl no Webhook URL override
description no Short description (max 256)
expiresInSec no Expiry window (60–86400)
gatewayId no Gateway UUID when the API key is not gateway-bound
customerMobile no Buyer mobile (09… or +98…)
customerFullName no Buyer name (max 128)

Prefer startPayUrl for redirect when present; otherwise use checkoutUrl.

Treat returnUrl as a browser return only. Always call verifyPayment (or getPayment) before fulfilling.

Errors

Failed HTTP responses throw GardeshPay\GardeshPayException with HTTP status and problem-details fields when available.

Authentication

Every request is signed with your API key and HMAC secret. The client sets:

  • X-Api-Key
  • X-Timestamp
  • X-Nonce
  • X-Signature
  • Idempotency-Key on create, verify, and refund

Canonical string:

METHOD
PATH?QUERY
TIMESTAMP
NONCE
SHA256_HEX(body)

X-Signature is Base64(HMAC-SHA256(secret, canonical)).

Webhooks

Webhooks are notifications only. Confirm payment status with verifyPayment before fulfillment.

use GardeshPay\Webhook;

$result = Webhook::verify(
    getenv('GARDESHPAY_WEBHOOK_SECRET'),
    $rawBody,
    getallheaders()
);

if (!$result['ok']) {
    http_response_code(401);
    echo $result['reason'];
    exit;
}

Development

composer install
composer test

License

MIT © GardeshPay