payop/sdk-php

PayOp PHP SDK

v0.0.1 2019-03-05 08:09 UTC

This package is auto-updated.

Last update: 2019-09-05 22:33:21 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads License

Requirements

PHP 5.6.0 and later.

Composer

You can install the SDK via Composer. Run the following command:

composer require payop/sdk-php

To use the SDK, use Composer's autoload:

require_once('vendor/autoload.php');

Manual Installation

If you do not wish to use Composer, you can download the latest release. Then, to use the SDK, include the autoload.php file.

require_once('vendor/autoload.php');

Dependencies

The SDK require the following extensions in order to work properly:

  • curl, although you can use your own non-cURL client if you prefer
  • json

If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.

Examples

Create payment

<?php
use Payop\Exception\RequestErrorException;
use Payop\Exception\ValidationException;
use Payop\Model\PaymentCustomer;
use Payop\Model\PaymentOrder;
use Payop\Model\PaymentRequest;
use Payop\SDK;

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

$order = PaymentOrder::create('TEST_SDK_1', 101.04, 'USD');
$customer = PaymentCustomer::create('test@email.com');
$paymentRequest = new PaymentRequest($order, $customer);

$sdk = new SDK('public key', 'secret key');
try {
    $redirectUrl = $sdk->createPayment($paymentRequest);
} catch (ValidationException $e) {
    echo $e->getMessage().PHP_EOL;
} catch (RequestErrorException $e) {
    echo "{$e->getMessage()}: {$e->getErrorCode()}".PHP_EOL;
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    echo $e->getMessage().PHP_EOL;
}

echo $redirectUrl.PHP_EOL;

# Result contains link: https://payop.com/en/payments/v1.1/payment/pay/1debf20a-3f1c-11e9-b00e-0656050605

Result

https://payop.com/en/payments/v1.1/payment/pay/1debf20a-3f1c-11e9-b00e-0656050605

Get Merchant payment methods

<?php

use Payop\Exception\RequestErrorException;
use Payop\Exception\ValidationException;
use Payop\SDK;

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

$sdk = new SDK('public key', 'secret key');
try {
    $collection = $sdk->getPaymentMethods();
} catch (ValidationException $e) {
    echo $e->getMessage().PHP_EOL;
} catch (RequestErrorException $e) {
    echo "{$e->getMessage()}: {$e->getErrorCode()}".PHP_EOL;
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    echo $e->getMessage().PHP_EOL;
}

var_dump($collection);

Result

class Payop\Collection#33 (1) {
  protected $items =>
  array(70) {
    [0] =>
    class Payop\Model\PaymentMethod#30 (5) {
      protected $title =>
      string(8) "7 ELEVEN"
      protected $image =>
      string(69) "https://payop.com/public/front/image/payment_methods/seven_eleven.jpg"
      protected $id =>
      string(36) "1de64ea0-a210-11e8-a646-379802902746"
      protected $type =>
      string(4) "cash"
      protected $config =>
      class Payop\Model\PaymentMethodConfig#23 (1) {
        ...
      }
    }
    ...

Get Transaction Info

<?php

use Payop\Exception\RequestErrorException;
use Payop\Exception\ValidationException;
use Payop\SDK;

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

$sdk = new SDK('application-101', '8b30a6c9de9de06c5aae6e2aaddfcca7');
try {
    $collection = $sdk->getTransaction(912164324);
    // OR $collection = $sdk->getTransaction('445bbbbbb45bbbbbbbbbbbbb3434545');
} catch (ValidationException $e) {
    echo $e->getMessage().PHP_EOL;
} catch (RequestErrorException $e) {
    echo "{$e->getMessage()}: {$e->getErrorCode()}".PHP_EOL;
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    echo $e->getMessage().PHP_EOL;
}

var_dump($collection);

Result

class Payop\Model\Transaction#33 (8) {
  protected $id =>
  int(912164324)
  protected $txid =>
  string(64) "445bbbbbb45bbbbbbbbbbbbb3434545"
  protected $status =>
  string(5) "error"
  protected $order =>
  class Payop\Model\TransactionOrder#36 (3) {
    private $id =>
    string(5) "orderid"
    private $amount =>
    double(1)
    private $currency =>
    string(3) "USD"
  }
  protected $language =>
  string(2) "en"
  protected $error =>
  NULL
  protected $isDeferred =>
  bool(false)
  protected $deferredMessage =>
  NULL
}