paylot/paylot-php

Paylot API 的 PHP 包装器

v1.0.0 2019-09-10 17:23 UTC

This package is auto-updated.

Last update: 2024-09-09 02:36:05 UTC


README

Paylot 提供的 PHP API 包装器。

Paylot

需求

  • 要求 Guzzle 6.3.0 或更高版本(除非使用 Guzzle)
  • PHP 5.4.0 或更高版本
  • OpenSSL v1.0.1 或更高版本

安装

通过 Composer

    $ composer require paylot/paylot-php

通过下载

发行页面 下载一个版本。解压后

    require 'path/to/src/autoload.php';

用法

使用时,请遵循以下步骤。

0. 前提条件

确认您的服务器可以与 Paylot 的服务器建立 TLSv1.2 连接。大多数最新软件都具备此功能。如果遇到任何 SSL 错误,请联系您的服务提供商以获取指导。不要禁用 SSL 伙伴验证!

0b. 秘密密钥

请确保您手头上有 Paylot 的秘密密钥。您可以从您的业务资料中获取该密钥。

1. 验证交易

交易成功后,请在给予价值之前验证交易。

    $reference = isset($_GET['reference']) ? $_GET['reference'] : '';
    if(!$reference){
      die('No reference supplied');
    }

    // initiate the Library's Paystack Object
    $paylot = new Paylot\Paylot(SECRET_KEY);
    try
    {
      // verify using the library
      $tranx = $paylot->transaction->verify($reference);
    } catch(\Paylot\Exceptions\ApiResponseException $e){
      print_r($e->getResponseObject());
      die($e->getMessage());
    }

    if ($tranx->sent) {
      // Payment has been made. You can give value
    }
    
    if ($tranx->confirmed) {
      // Payment has been confirmed on blockchain. 
      // If you don't give value here, I don't know what you are waiting for.
    }