credoteam/credo

此包用于与CredoCentral.com API通信

dev-main 2022-02-09 00:00 UTC

This package is auto-updated.

Last update: 2024-09-07 14:51:56 UTC


README

此包用于与CREDO RESTful API通信。 Credo

CREDO API上有其他可用资源点,例如:

  • 交易
  • 通过卡进行3D安全支付
  • 验证卡号
  • 直接卡收费
  • 等等

仅列举几个,目前此包中仅提供了交易资源。开发正在进行中,而发布是稳定的。


要求

  • Curl

安装

通过Composer

$ composer require credoteam/credo:dev-main

如果您使用框架,请检查您的文档以了解如何自动加载供应商包,否则请将以下内容添加到源文件顶部;

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

进行交易/接收付款

启动Credo交易

use Credoteam\Credo\Transaction;
use Credoteam\Credo\Helpers\Debugger;
use Credoteam\Credo\Helpers\Requesters;

$publicKey =  "pk_demo-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxx-d";
$secretKey = "sk_demo-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxx-d";

// creating the transaction object
$Transaction = new Transaction( $publicKey );

初始化交易

使用初始化请求将数据/负载/请求正文设置为post。所需的最小数据是电子邮件和金额。

// Set data to post using array
$data = [
  "amount"=> 3000,
  "currency"=> "NGN",
  "redirectUrl"=> "https://:8080/test-credo/welcome/",
  "transRef"=> "748rbrio4823ruoqedb9h4378e", //you can send your transaction ref or allow Credo generate for you
  "paymentOptions"=> "CARD",
  "customerEmail"=> "adiegodswill17@gmail.com",
  "customerName"=> "Adie Godswill",
  "customerPhoneNo"=> "09021960905"
];

$response = $Transaction->initialize($data);

如果您想获取Credo发送的200OK原始对象,请将initialize()的第二个参数设置为true,如下所示

// Set data to post using this method
$response =
        $Transaction
            ->setEmail( 'adiegodswill17@gmail.com' )
            ->setAmount( 23000 )
            ->initialize([], true);

现在进行到支付页面(使用redirectUrl重定向)
注意:建议调试$response或检查是否设置了redirectUrl,并保存您的交易参考代码。这有助于验证交易状态

// recommend to save Transaction reference in database and do a redirect
$transRef = $response->transRef;
// redirect
Http::redirect($response->redirectUrl);

如果您使用框架,建议您使用框架提供的反向路由/重定向功能

验证交易

您还需要再次创建交易对象。
此方法将返回交易对象,但如果未传入作为参数的$transRef已保存且无法猜测,则返回false。使用verify()将需要在响应对象上进行手动检查

// creating the transaction object
$Transaction = new Transaction( $secretKey );

// Set data to post using this method
$response = $Transaction->verify($transRef);

// Debuging the $response
Debugger::print_r( $response);

或者

// This method does the check for you and return `(bool) true|false`
$response = $Transaction->isSuccessful();

上述两种方法试图猜测您的交易$transRef,但强烈建议您将交易$transRef作为参数传递给方法,如下所示

// This method does the check for you and return `(bool) true|false`
$response = $Transaction->isSuccessful($transRef);

直接卡收费

将数据/负载/请求正文设置为post,以直接收费请求。

// Set data to post using array
$data = [
  "orderAmount" => 400,
  "orderCurrency" => "NGN",
  "cardNumber" => 4242424242424242,
  "expiryMonth" => 1,
  "expiryYear" => 22,
  "securityCode" => 439,
  "transRef" => "748rbri4823ruoqedb9h435",
	"customerEmail" => "adiegodswill17@gmail.com",
	"customerName" => "Adie Godswill",
	"customerPhoneNo" => "09021960905"
];

// creating the transaction object
$Transaction = new Transaction( $secretKey );

// Set data to post using this method
$response = $Transaction->direct_charge($data);

验证卡号

将数据/负载/请求正文设置为post,以验证卡号请求。

// Set data to post using array
$data = [
 	"cardNumber" => 4242424242424242,
 	"orderCurrency" => "NGN",
  "paymentSlug" => "pIEiYn8xxxxxxxxxxxxx"
];

// creating the transaction object
$Transaction = new Transaction( $secretKey );

// Set data to post using this method
$response = $Transaction->verify_card_number($data);

通过卡进行3D安全支付

将数据/负载/请求正文设置为post,以执行3D安全支付请求。

// Set data to post using array
$data = [
  "amount" => 4500,
  "currency" => "NGN",
  "redirectUrl" => "https:///go",
  "transRef" => "748389842939e3",
  "paymentOptions" => "CARD",
  "customerEmail" => "adiegodswill17@gmail.com",
  "customerName" => "Adie Godswill",
  "customerPhoneNo" => "09021960905"
];

// creating the transaction object
$Transaction = new Transaction( $secretKey );

// Set data to post using this method
$response = $Transaction->payment_3ds($data);

贡献

如果您似乎理解了架构,欢迎您进行分支并拉取,或者您可以等待一段时间,直到我们提供惯例文档。

许可

GNU GPLV3