schibsted / sdk-php-payment-gateway
Schibsted ePayment Platform SDK
Installs: 11 548
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 11
Forks: 0
Open Issues: 0
Requires
- php: >=5.6
- ext-curl: *
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is not auto-updated.
Last update: 2024-12-22 06:13:25 UTC
README
Install with composer
composer require schibsted/sdk-php-payment-gateway
(install this library)composer require schibsted/sdk-php
(install SPiD sdk required for getting authentication tokens)
Usage
<?php use schibsted\payment\sdk\response\Success; use schibsted\payment\sdk\response\Response; use schibsted\payment\resources\Order; $spid_config = [ VGS_Client::CLIENT_ID => '<YOUR ID>', VGS_Client::CLIENT_SECRET => '<YOUR SECRET>', VGS_Client::CLIENT_SIGN_SECRET => '<YOUR SIGNATURE SECRET>', VGS_Client::PRODUCTION => false, VGS_Client::API_VERSION => 2, ]; $spid_client = new VGS_Client($spid_config); $oauth_token = $spid_client->auth(); $payment_gateway_config = [ 'host' => 'https://api-gateway-stage.payment.schibsted.no', 'port' => '443', 'adapter_config' => [ CURLOPT_CONNECTTIMEOUT_MS => 1000], 'token' => $oauth_token ]; $amount = 12000; // 120 euro, amount in CENT $vat = 2500; // 25%, amount in hundredths $order_res = new Order($payment_gateway_config); $data = [ "purchaseFlow" => "SALE", "fromPaymentProviderInfo" => [ [ "ppaProvider" => "ADYEN_CARD", "storedPaymentMethodId" => $method_id ] ], "description" => "Some description of a payment", "fromUserIp" => "127.0.0.1", "currency" => "EUR", "clientId" => $this->client_id, "merchantId" => $merchant_id, "transactionReference" => uniqid(), "orderItems" => [ [ "quantity" => 1, "type" => "DEFAULT", "price" => $amount, "vat" => $vat, "name" => "Some name of item", "description" => 'Some description of item', ] ] ]; $result = $order_res->create($data); if ($result instanceof Success === false) { $content = $result->getContent(); $c = $content['errorCode'] ?? '-'; $m = $content['errorMessage'] ?? 'unknown'; $r = $content['requestId'] ?? '<NO REQUEST ID>'; throw new \Exception("Create Order failed: $c : $r : $m"); } $order = $result->getContent(); $order_id = $order['id']; if (is_numeric($order_id) == false) { throw new \Exception("Order object not valid"); } $result = $order_res->initialize($order_id); if ($result instanceof Success === false) { $content = $result->getContent(); $c = $content['errorCode'] ?? '-'; $m = $content['errorMessage'] ?? 'unknown'; $r = $content['requestId'] ?? '<NO REQUEST ID>'; throw new \Exception("Order Init failed: $c : $r : $m"); } $result = $order_res->complete($order_id); if ($result instanceof Success === false) { $content = $result->getContent(); $c = $content['errorCode'] ?? '-'; $m = $content['errorMessage'] ?? 'unknown'; $r = $content['requestId'] ?? '<NO REQUEST ID>'; throw new \Exception("Order Complete failed: $c : $r : $m"); } return $result->getContent();