wowmarketing/webpay-php

GP Webpay API 包装器

1.1.1 2016-01-26 09:36 UTC

This package is auto-updated.

Last update: 2024-09-22 03:36:29 UTC


README

Build Status

GP Webpay 支付 提供的完整功能的 PHP SDK。

安装

安装 GP Webpay PHP SDK 的最佳方法是使用 Composer

$ composer require wowmarketing/webpay-php dev-master

配置

$signer = new \WOWMarketing\Webpay\Signer(
  $privateKeyFilepath,    // Path of private key.
  $privateKeyPassword,    // Password for private key.
  $publicKeyFilepath      // Path of public key.
);
    
$api = new \WOWMarketing\Webpay\Api(
  $merchantNumber,    // Merchant number.
  $webpayUrl,         // URL of webpay.
  $signer             // instance of \WOWMarketing\Webpay\Signer.
);

创建支付

创建支付 URL

use \WOWMarketing\Webpay\PaymentRequest;

$request = new PaymentRequest(...);

$url = $api->createPaymentRequestUrl($request); // $api instance of \WOWMarketing\Webpay\Api

// use $url as you want. In most cases for redirecting to GP Webpay.

验证支付响应

use \WOWMarketing\Webpay\PaymentResponse;
use \WOWMarketing\Webpay\Exception;
 
$response = new PaymentResponse(...); // fill response with response parameters (from request).
 
try {
  $api->verifyPaymentResponse($response);
} 
catch (PaymentResponseException $e) {
  // PaymentResponseException has $prCode, $srCode for properties for logging GP Webpay response error codes.
}
catch (Exception $e) {
  // Digest is not correct.
}

##开发

GP Webpay PHP SDK 通过 docker-compose 命令在 Docker 容器中开发。

示例

$ docker-compose run --rm default install  # install deps via composer
$ docker-compose run --rm default  # runs tests in container

连接到容器

$ docker-compose run --rm default bash # runs bash in container and attach tty