begateway/begateway-api-php

BeGateway PHP API library

4.5.0 2021-08-31 06:17 UTC

README

Build Status Master

Requirements

PHP 5.6/7.0/7.1/7.2/7.3/7.4

Test data

Shop without 3-D Secure

  • Shop Id 361
  • Shop secret key b8647b68898b084b836474ed8d61ffe117c9a01168d867f24953b776ddcb134d

Shop with 3-D Secure

  • Shop Id 362
  • Shop secret key 9ad8ad735945919845b9a1996af72d886ab43d3375502256dbf8dd16bca59a4e

Test data set

  • Card name John Doe
  • Card expiry month 01 to get a success payment
  • Card expiry month 10 to get a failed payment
  • CVC 123

Test card numbers

Refer to the documentation https://doc.begateway.com/test-integration#test-card-number for valid test card numbers.

Getting started

Setup

Before to use the library classes you must configure it. You have to setup values of variables as follows:

  • shopId
  • shopKey
  • gatewayBase
  • checkoutBase

This data you will receive from your payment processor.

\BeGateway\Settings::$shopId  = 361;
\BeGateway\Settings::$shopKey = 'b8647b68898b084b836474ed8d61ffe117c9a01168d867f24953b776ddcb134d';
\BeGateway\Settings::$gatewayBase = 'https://demo-gateway.begateway.com';
\BeGateway\Settings::$checkoutBase = 'https://checkout.begateway.com';

Hosted payment page

Simple usage looks like:

require_once __DIR__ . 'PATH_TO_INSTALLED_LIBRARY/lib/BeGateway.php';
\BeGateway\Settings::$shopId  = 361;
\BeGateway\Settings::$shopKey = 'b8647b68898b084b836474ed8d61ffe117c9a01168d867f24953b776ddcb134d';

\BeGateway\Logger::getInstance()->setLogLevel(\BeGateway\Logger::INFO);

$transaction = new \BeGateway\GetPaymentToken;

$transaction->money->setAmount(1.00);
$transaction->money->setCurrency('EUR');
$transaction->setDescription('test');
$transaction->setTrackingId('my_custom_variable');
$transaction->setLanguage('en');
$transaction->setNotificationUrl('http://www.example.com/notify');
$transaction->setSuccessUrl('http://www.example.com/success');
$transaction->setDeclineUrl('http://www.example.com/decline');
$transaction->setFailUrl('http://www.example.com/fail');
$transaction->setCancelUrl('http://www.example.com/cancel');

$transaction->customer->setFirstName('John');
$transaction->customer->setLastName('Doe');
$transaction->customer->setCountry('LV');
$transaction->customer->setAddress('Demo str 12');
$transaction->customer->setCity('Riga');
$transaction->customer->setZip('LV-1082');
$transaction->customer->setIp('127.0.0.1');
$transaction->customer->setEmail('john@example.com');

$response = $transaction->submit();

if ($response->isSuccess() ) {
  header("Location: " . $response->getRedirectUrl() );
}

Payment request via direct API

Simple usage looks like:

require_once __DIR__ . 'PATH_TO_INSTALLED_LIBRARY/lib/BeGateway.php';
\BeGateway\Settings::$shopId  = 361;
\BeGateway\Settings::$shopKey = 'b8647b68898b084b836474ed8d61ffe117c9a01168d867f24953b776ddcb134d';

\BeGateway\Logger::getInstance()->setLogLevel(\BeGateway\Logger::INFO);

$transaction = new \BeGateway\Payment;

$transaction->money->setAmount(1.00);
$transaction->money->setCurrency('EUR');
$transaction->setDescription('test order');
$transaction->setTrackingId('my_custom_variable');

$transaction->card->setCardNumber('4200000000000000');
$transaction->card->setCardHolder('John Doe');
$transaction->card->setCardExpMonth(1);
$transaction->card->setCardExpYear(2030);
$transaction->card->setCardCvc('123');

$transaction->customer->setFirstName('John');
$transaction->customer->setLastName('Doe');
$transaction->customer->setCountry('LV');
$transaction->customer->setAddress('Demo str 12');
$transaction->customer->setCity('Riga');
$transaction->customer->setZip('LV-1082');
$transaction->customer->setIp('127.0.0.1');
$transaction->customer->setEmail('john@example.com');

$response = $transaction->submit();

if ($response->isSuccess()) {
  print("Status: " . $response->getStatus() . PHP_EOL);
  print("Transaction UID: " . $response->getUid() . PHP_EOL);
} elseif ($response->isFailed()) {
  print("Status: " . $response->getStatus() . PHP_EOL);
  print("Transaction UID: " . $response->getUid() . PHP_EOL);
  print("Reason: " . $response->getMessage() . PHP_EOL);
} else {
  print("Status: error" . PHP_EOL);
  print("Reason: " . $response->getMessage() . PHP_EOL);
}

Examples

See the examples directory for integration examples of different transactions.

Documentation

Visit https://doc.begateway.com for up-to-date documentation.

Tests

To run tests

php -f ./test/BeGateway.php