承接 gnurlan/gpwebpay 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gnurlan/gpwebpay

Composer 安装命令:

composer require gnurlan/gpwebpay

包简介

GP WepPay payment gateway for a standard card payment

README 文档

README

Build Status Test Coverage Latest Stable Version License

GPWebPay is a PHP library for online payments via GPWebPay service

If your are using Nette framework, you may want Pixidos/GPWebPay Nette extension instead.

Quickstart

Set up & usage

<?php

namespace App\Http\Controllers;

use Auth;
use App;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

use Granam\GpWebPay\Settings as GpSettings;
use Granam\GpWebPay\DigestSigner;
use Granam\GpWebPay\CardPayResponse;
use Granam\GpWebPay\Codes\CurrencyCodes;
use Alcohol\ISO4217 as IsoCurrencies;
use Granam\GpWebPay\CardPayRequestValues;
use Granam\GpWebPay\CardPayRequest;
use Granam\GpWebPay\Exceptions\GpWebPayErrorByCustomerResponse;
use Granam\GpWebPay\Exceptions\GpWebPayErrorResponse;
use Granam\GpWebPay\Exceptions\ResponseDigestCanNotBeVerified;
use Granam\GpWebPay\Exceptions\Exception as GpWebPayException;

class PayController extends Controller
{
    const MERCHANT_NUMBER     = '123456789'; // your 'merchant number' given to you by GP WebPay
    const GP_PRIVATE_KEY      = 'your_private_key_downloaded_from_gp_web_pay.pem';
    const GP_PRIVATE_KEY_PASS = 'TopSecretPasswordForPrivateKey';
    const GP_PUBLIC_KEY       = 'gp_web_pay_server_public_key_also_downloaded_from_gp_web_pay.pem';

    protected $digestSigner;
    protected $settings;

    public function __construct()
    {
        $this->settings = GpSettings::createForProduction(
            storage_path(self::GP_PRIVATE_KEY),
            self::GP_PRIVATE_KEY_PASS,
            storage_path(self::GP_PUBLIC_KEY),
            self::MERCHANT_NUMBER
        // without explicit URL for response the current will be used - INCLUDING query string
        );
        $this->digestSigner = new DigestSigner($this->settings);
    }

    public function request()
    {
        $currencyCodes = new CurrencyCodes(new IsoCurrencies());
        try {
            $cardPayRequestValues = CardPayRequestValues::createFromArray($_GET, $currencyCodes);
            $cardPayRequest = new CardPayRequest($cardPayRequestValues, $this->settings, $this->digestSigner);
        } catch (GpWebPayException $exception) {
            /* show an apology to the customer
             * like "we are sorry, our payment gateway is temporarily unavailable" and log it, solve it */
            exit();
        }
        print '<html><body><form method="post" action="' . $cardPayRequest->getRequestUrl() . '">';
        foreach ($cardPayRequest as $name => $value) {
            print '<input type="hidden" name="' . $name . '" value="' . $value . '">';
        }
        print '<input type="submit" value="Confirm order"></form></body></html>';

    }

    public function response()
    {
        try {
            $response = CardPayResponse::createFromArray($_POST, $this->settings, $this->digestSigner);
        } catch(GpWebPayErrorByCustomerResponse $gpWebPayErrorByCustomerResponse) {
            // some pretty error box for customer information about HIS mistake like invalid card number
            /**
             * WARNING: do not rely blindly on this detection - for example if YOU (developer) are sending
             * card number in a hidden field, because the customer provided it to its account before and
             * does not need to enter it again, but the card number has been refused by GP WebPay,
             * you will show to the customer confusing message about an invalid card number,
             * although he does not enter it.
             * For full list of auto-detected customer
             * mistakes @see GpWebPayErrorByCustomerResponse::isErrorCausedByCustomer
             */
            echo $gpWebPayErrorByCustomerResponse->getLocalizedMessage();
        } catch(GpWebPayErrorResponse $gpWebPayErrorResponse) {
            /* GP WebPay refuses request by OUR (developer) mistake like duplicate order number
             * - show an apology to the customer and log this, solve this */
        } catch(ResponseDigestCanNotBeVerified $responseDigestCanNotBeVerified) {
            /* values in response have been changed(!),
             * show an apology (or a warning?) to the customer and probably log this for evidence */
        } catch(GpWebPayException $gpWebPayException) { // EVERY exception share this interface
            /* some generic error like processing error on GP WebPay server,
             * show an apology to the customer and log this, solve this */
        }
        /**
         * its OK, lets process $response->getParametersForDigest();
         * @see \Granam\GpWebPay\CardPayResponse::getParametersForDigest
         */
    }

}

Troubleshooting

Almost all possible error cases are covered clearly by many of exceptions, but some are so nasty so they can not be:

  • after sending a request to GP WebPay you see just a logo and HTTP response code is 401
    • probably the URL for response you provided to GP WebPay in URL parameter is not valid in the point of view of GP WebPay
      • ensure that URL exists and there is NO redirection, like https://www.github.com to https://github.com/ with trailing slash (don't believe your eyes in a browser address bar, the trailing slash is often hidden there)

For tests against testing payment gateway you can use payment card

  • Card number: 4056070000000008
  • Card valdity: 12/2020
  • CVC2: 200
  • 3D Secure password: password

Installation

composer require gnurlan/gpwebpay

(requires PHP 7.0+)

Credits

This library originates from Pixidos/GPWebPay library, which has same functionality but can be used only as a Nette framework extension. All credits belongs to the author Ondra Votava from Pixidos.

Nevertheless I am grateful to him for sharing that library publicly. Please more of such people.

gnurlan/gpwebpay 适用场景与选型建议

gnurlan/gpwebpay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 08 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「payment」 「checkout」 「pay」 「webpay」 「gp」 「gp webpay」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 gnurlan/gpwebpay 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gnurlan/gpwebpay 我们能提供哪些服务?
定制开发 / 二次开发

基于 gnurlan/gpwebpay 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 39
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 17
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2020-08-27