begateway/begateway-api-php

BeGateway PHP API库

5.1.1 2024-05-21 18:22 UTC

README

要求

PHP >=7.3

测试数据

不使用3-D Secure的商店

  • 商店ID 361
  • 商店密钥 b8647b68898b084b836474ed8d61ffe117c9a01168d867f24953b776ddcb134d

使用3-D Secure的商店

  • 商店ID 362
  • 商店密钥 9ad8ad735945919845b9a1996af72d886ab43d3375502256dbf8dd16bca59a4e

测试数据集

  • 卡名 John Doe
  • 卡到期月份 01 可获得成功支付
  • 卡到期月份 10 可获得失败支付
  • CVC 123

测试卡号

有关有效测试卡号的详细信息,请参阅文档https://doc.begateway.com/test-integration#test-card-number

入门指南

设置

在使用库类之前,您必须进行配置。您需要设置如下变量的值:

  • shopId
  • shopKey
  • gatewayBase
  • checkoutBase

这些数据将由您的支付处理器提供。

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

托管支付页面

简单用法如下

<?php

require_once __DIR__ . 'PATH_TO_INSTALLED_LIBRARY/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() );
}

通过直接API发起支付请求

简单用法如下

<?php

require_once __DIR__ . 'PATH_TO_INSTALLED_LIBRARY/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);
}

示例

请参阅示例目录,以了解不同交易集成的示例。

文档

请访问https://doc.begateway.com获取最新文档。

测试

要运行测试

./vendor/bin/phpunit