1. Go to this page and download the library: Download xgenious/paymentgateway 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/ */
namespace Xgenious\Paymentgateway\Base\Gateways;
use Xgenious\Paymentgateway\Base\PaymentGatewayBase;
use Xgenious\Paymentgateway\Traits\CurrencySupport;
use Xgenious\Paymentgateway\Traits\PaymentEnvironment;
use Xgenious\Paymentgateway\Traits\ConvertUsdSupport; // is)
public function setApiKey(string $key): static
{
$this->api_key = $key;
return $this;
}
public function setSecretKey(string $key): static
{
$this->secret_key = $key;
return $this;
}
// 3. Private getters
private function getApiKey(): string { return $this->api_key; }
private function getSecretKey(): string { return $this->secret_key; }
// 4. Implement: convert amount to the unit the gateway expects
public function charge_amount($amount): float|int
{
// If the site currency is natively supported, use it directly.
// Otherwise, convert to USD (or the gateway's base currency).
if (in_array($this->getCurrency(), $this->supported_currency_list(), true)) {
return $amount;
}
return $this->get_amount_in_usd($amount);
}
// 5. Implement: initiate a payment and redirect the customer
public function charge_customer(array $args): mixed
{
$amount = $this->charge_amount($args['amount']);
// Call the gateway SDK / HTTP API to create a payment session.
// $args keys: amount, title, description, ipn_url, order_id,
// track, cancel_url, success_url, email, name, payment_type
$response = YourGatewaySdk::createPayment([
'amount' => $amount,
'currency' => $this->charge_currency(),
'redirect_url'=> $args['success_url'],
'webhook_url' => $args['ipn_url'],
'reference' => $args['order_id'],
]);
// Store anything you need to verify the payment later
session()->put('yourgateway_payment_id', $response->id);
session()->put('yourgateway_order_id', $args['order_id']);
// Return a redirect to the hosted payment page
return redirect($response->payment_url);
}
// 6. Implement: verify the payment on the IPN/callback route
public function ipn_response(array $args = []): array
{
$payment_id = session()->get('yourgateway_payment_id');
$order_id = session()->get('yourgateway_order_id');
session()->forget(['yourgateway_payment_id', 'yourgateway_order_id']);
$payment = YourGatewaySdk::getPayment($payment_id);
if ($payment->status === 'paid') {
// verified_data() merges ['status' => 'complete'] with your array
return $this->verified_data([
'transaction_id' => $payment->id,
'order_id' => $order_id,
]);
}
return ['status' => 'failed', 'order_id' => $order_id];
}
// 7. Implement: currencies this gateway natively accepts
public function supported_currency_list(): array
{
return ['USD', 'EUR', 'GBP']; // add all currencies the gateway accepts
}
// 8. Implement: return the currency that will actually be charged
public function charge_currency(): string
{
return $this->getCurrency();
}
// 9. Implement: a lowercase slug for this gateway
public function gateway_name(): string
{
return 'yourgateway';
}
}
use Xgenious\Paymentgateway\Base\Gateways\YourGatewayPay;
// inside the class:
public function yourgateway(): YourGatewayPay
{
return new YourGatewayPay();
}
use Xgenious\Paymentgateway\Base\RecurringSupport;
class YourGatewayPay extends PaymentGatewayBase implements RecurringSupport
{
public function charge_customer_recurring(array $args): mixed { ... }
public function ipn_response_recurring(array $args = []): array { ... }
}