inxy-payments / merchant-sdk
SDK for INXY Payments merchant api
Installs: 2 738
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.4 || ^8.0
- ext-json: *
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- dev-master
- v3.2.0
- v3.1.9
- v3.1.8
- v3.1.7
- v3.1.6
- v3.1.5
- v3.1.4
- v3.1.3
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.0
- v2.x-dev
- v2.2.0
- v2.1.10
- v2.1.9
- v2.1.8
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.1
- v2.0.0
- v1.x-dev
- v1.2.0
- v1.1.11
- v1.1.10
- v1.1.9
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.0
- dev-v2.x-add-actions
- dev-v1.x_add-actions
- dev-actions
This package is auto-updated.
Last update: 2024-05-06 10:32:53 UTC
README
Setup/Install
Install through Composer.
composer require inxy-payments/merchant-sdk
Example redirect to pay page
$apiKey = 'Your api key here'; $config = new Config(Environment::Sandbox, $apiKey, ApiVersion::v1); $merchantSDK = new MerchantSDK($config); $orderAmountInUSD = 20; $orderName = 'Order #1'; $customer = new Customer('example@mail.com', 'John', 'Doe'); $sessionRequest = new MultiCurrencySessionRequest($orderAmountInUSD, $orderName, FiatCurrencyCode::USD); $defaultCryptocurrency = new Cryptocurrency(CurrencyCode::USDT, Blockchain::Ethereum, CoinType::ERC20); $cryptocurrencies = []; $cryptocurrencies[] = $defaultCryptocurrency; $cryptocurrencies[] = new Cryptocurrency(CurrencyCode::USDT, Blockchain::BinanceSmartChain, CoinType::BEP20); $cryptocurrencies[] = new Cryptocurrency(CurrencyCode::BTC, Blockchain::Bitcoin, CoinType::Native); $cryptocurrencies[] = new Cryptocurrency(CurrencyCode::ETH, Blockchain::Ethereum, CoinType::Native); $cryptocurrencies[] = new Cryptocurrency(CurrencyCode::DOGE, Blockchain::Dogecoin, CoinType::Native); $cryptocurrencies[] = new Cryptocurrency(CurrencyCode::USDC, Blockchain::Ethereum, CoinType::ERC20); $sessionRequest->setCryptocurrencies($cryptocurrencies); $sessionRequest->setDefaultCryptocurrency($defaultCryptocurrency); $sessionRequest->setOrderId('order_123'); $sessionRequest->setPostbackUrl('https://example.com/postback'); $sessionRequest->setCancelUrl('https://example.com/cancel'); $sessionRequest->setSuccessUrl('https://example.com/success'); $sessionRequest->setCustomer($customer); $sessionResponse = $merchantSDK->createMultiCurrencySession($sessionRequest); header('Location: ' . $sessionResponse->getRedirectUri());
Example handle webhook
function handleWebhooks($request) { $secretKey = 'Your secret key here'; $validator = new Validator($secretKey); $signedHash = $request->headers['X-INXY-Payments-Signature']; $payload = $request->getBody()->getContents(); // fetch json from your request if (!$validator->isValid($payload, $signedHash)) { throw new BadRequestException('No valid webhook'); } $data = json_decode($payload, false); switch ($data->name) { case EventName::PaymentsInit: handlePaymentsInitWebhook($data); break; case EventName::PaymentsWaitingConfirmations: handlePaymentsWaitingConfirmationsWebhook($data); break; case EventName::PaymentsReceived: handlePaymentsReceivedWebhook($data); break; default: throw new InvalidArgumentException('Undefined webhook name'); } } function handlePaymentsInitWebhook(stdClass $webhookData) { $webhook = PaymentsInitWebhookFactory::create($webhookData); if ($webhook->data->paymentIntent->status === PaymentIntentStatus::WaitingPayment) { /** Waiting first payment */ } if ($webhook->data->paymentIntent->status === PaymentIntentStatus::WaitingPaymentPart) { /** Waiting part payment after partially paid */ } /** Your code here */ } function handlePaymentsWaitingConfirmationsWebhook(stdClass $webhookData) { $webhook = PaymentsWaitingConfirmationsWebhookFactory::create($webhookData); /** Your code here */ } function handlePaymentsReceivedWebhook(stdClass $webhookData) { $webhook = PaymentsReceivedWebhookFactory::create($webhookData); if ($webhook->data->paymentIntent->status === PaymentIntentStatus::Paid) { /** Success payment code */ } if ($webhook->data->paymentIntent->status === PaymentIntentStatus::PartiallyPaid) { /** Partially paid actions */ } /** Your code here */ }