1. Go to this page and download the library: Download zaver/sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Zaver\SDK\Refund;
use Zaver\SDK\Object\RefundCreationRequest;
const API_KEY = '<your API key>';
const CALLBACK_TOKEN = '<your callback token>';
const IS_TEST_ENVIRONMENT = true;
$api = new Refund(API_KEY, IS_TEST_ENVIRONMENT);
// It does most likely not make any sense to fetch the payment first - this is just for
// showing the relation between a payment and a refund.
$payment = $api->getPaymentStatus('463d6d10-4c0f-424b-b804-8e95114864dd');
$urls = MerchantUrls::create()
->setCallbackUrl('https://example.com/api/refund-callback');
$request = RefundCreationRequest::create()
->setPaymentId($payment->getPaymentId())
->setRefundAmount($payment->getAmount())
->setDescription('Mr Fancy Pants changed his mind')
->setMerchantUrls($urls);
foreach($payment->getLineItems() as $paymentItem) {
$refundItem = RefundLineItem::create()
->setLineItemId($paymentItem->getId())
->setRefundTotalAmount($paymentItem->getTotalAmount())
->setRefundTaxAmount($paymentItem->getTaxAmount())
->setRefundTaxRatePercent($paymentItem->getTaxRatePercent())
->setRefundQuantity($paymentItem->getQuantity())
->setRefundUnitPrice($paymentItem->getUnitPrice());
$request->addLineItem($refundItem);
}
$refund = $api->createRefund($request);
echo $refund->getStatus();
// Outputs: PENDING_MERCHANT_APPROVAL