pmgw/payment-gateway-php7-sdk

大鱼支付网关 - PHP7 SDK

4.0.1 2024-09-19 11:58 UTC

README

仓库 github.com/bigfish-hu/payment-gateway-php7-sdk (bigfish/paymentgateway-php7-sdk) 已废弃,请避免使用。

请使用 https://github.com/pmgw-hu/payment-gateway-php7-sdk (pmgw/payment-gateway-php7-sdk) 代替。

大鱼支付网关 - PHP7 SDK

版本

4.0.1

要求

  • PHP 7.2
  • PHP cURL 扩展
  • PHP OpenSSL 扩展
  • PHP JSON 扩展

安装

大鱼支付网关可在 packagist.org 获取,因此您可以使用 composer 下载此库。

{
    "require": {
        "pmgw/payment-gateway-php7-sdk": "4.*"
    }
}

或运行

composer require pmgw/payment-gateway-php7-sdk

技术文档

https://docs.paymentgateway.hu/

源码

https://github.com/pmgw-hu/payment-gateway-php7-sdk

示例用法

基本配置

$config = new \BigFish\PaymentGateway\Config();
$config->storeName = "example store name";
$config->apiKey = "ExamPleApiKey";
$config->encryptPublicKey = "publicKeyGoesHere";
$config->testMode = true;

$paymentGateway = new \BigFish\PaymentGateway($config);

初始化请求

$init = new \BigFish\PaymentGateway\Request\Init();
$init->setProviderName(\BigFish\PaymentGateway::PROVIDER_CIB) // the chosen payment method
    ->setResponseUrl('http://your.companys.webshop.url/payment_gateway_response') // callback url
    ->setAmount(1234)
    ->setCurrency('HUF')
    ->setOrderId('ORD-1234') // your custom order id
    ->setUserId('USER-1234') // your custom user id
    ->setLanguage('HU');

$response = $paymentGateway->send($init);

开始请求

if (!$response->ResultCode == "SUCCESSFUL" || !$response->TransactionId) {
    // handle error here
}

$paymentGateway->send(
        (new \BigFish\PaymentGateway\Request\Start())->setTransactionId($response->TransactionId)
    );

结果请求

$result = $paymentGateway->send(
        (new \BigFish\PaymentGateway\Request\Result())->setTransactionId($_GET['TransactionId'])
    );

详细信息请求

$details = $paymentGateway->send(
        (new \BigFish\PaymentGateway\Request\Details())->setTransactionId($_GET['TransactionId'])
    );

关闭请求

$response = $paymentGateway->send(
        (new \BigFish\PaymentGateway\Request\Close())->setTransactionId($transactionId)
    );

退款请求

$response = $paymentGateway->send(
        (new \BigFish\PaymentGateway\Request\Refund())
            ->setTransactionId($transactionId)
            ->setAmount(100)
    );

支付请求

$payout = new \BigFish\PaymentGateway\Request\Payout();
$payout->setPayoutType(\BigFish\PaymentGateway::PAYOUT_TYPE_FUNDS_DISBURSEMENT)
    ->setReferenceTransactionId("783593c87fee4d372f47f53840028682")
    ->setAmount(200)
    ->setOrderId("BF-TEST-ORDER-REG") // your custom order id
    ->setAdditionalMessage("BF-TEST-PAYOUT-MESSAGE");

$response = $paymentGateway->send($payout);

取消支付注册请求

$response = $paymentGateway->send(
        (new \BigFish\PaymentGateway\Request\CancelPaymentRegistration())->setTransactionId($transactionId)
    );

取消所有支付注册请求

$response = $paymentGateway->send(
        (new \BigFish\PaymentGateway\Request\CancelAllPaymentRegistrations())
            ->setProviderName(\BigFish\PaymentGateway::PROVIDER_BORGUN2)
            ->setUserId('userId')
    );

初始化周期性支付 - InitRP

$initRP = new \BigFish\PaymentGateway\Request\InitRP();
$initRP->setReferenceTransactionId("783593c87fee4d372f47f53840028682")
    ->setResponseUrl("http://your.companys.webshop.url/payment_gateway_response") // callback url
    ->setAmount(200)
    ->setCurrency("HUF")
    ->setOrderId("BF-TEST-ORDER-REG") // your custom order id
    ->setUserId("BF-TEST-USER-REG");

$response = $paymentGateway->send($initRP);

StartRP 请求

if (!$response->ResultCode == "SUCCESSFUL" || !$response->TransactionId) {
    // handle error here
}

$result = $paymentGateway->send(
        (new \BigFish\PaymentGateway\Request\StartRP())->setTransactionId($response->TransactionId)
    );

创建支付链接 - PaymentLinkCreate

$paymentLink = new \BigFish\PaymentGateway\Request\PaymentLinkCreate();
$paymentLink->setProviderName(\BigFish\PaymentGateway::PROVIDER_CIB) // the chosen payment method
    ->setAmount(1234)
    ->setCurrency('HUF')
    ->setOrderId('ORD-1234') // your custom order id
    ->setUserId('USR-1234') // your customer id
    ->setLanguage('HU');

$response = $paymentGateway->send($paymentLink);

取消请求

$response = $paymentGateway->send(
        (new \BigFish\PaymentGateway\Request\PaymentLinkCancel())->setPaymentLinkName($paymentLinkName)
    );

详细信息请求

$response = $paymentGateway->send(
        (new \BigFish\PaymentGateway\Request\PaymentLinkDetails())->setPaymentLinkName($paymentLinkName)
    );

信息数据

基本用法

$infoObject = new \BigFish\PaymentGateway\Data\Info();

$infoCustomerGeneral = new \BigFish\PaymentGateway\Data\Info\Customer\InfoCustomerGeneral();
$infoCustomerGeneral->setFirstName("John")
    ->setLastName("Doe")
    ->setEmail("test@testmail.com");

$infoObject->setObject($infoCustomerGeneral); //add $infoCustomerGeneral to $infoObject
 
$infoShipping = new \BigFish\PaymentGateway\Data\Info\Order\InfoOrderShippingData();
$infoShipping->setFirstName("John")
    ->setLastName("Doe")
    ->setEmail("test@testmail.com")
    ->setPhoneCc("36")
    ->setPhone("801234567")
    ->setCity("Budapest");

$infoObject->setObject($infoShipping); //add $infoShipping to $infoObject
 
$infoOrderProductItem = new \BigFish\PaymentGateway\Data\Info\Order\InfoOrderProductItem();
$infoOrderProductItem->setSku("PMG055005")
    ->setName("Product11")
    ->setQuantity("10")
    ->setQuantityUnit("db")
    ->setUnitPrice("22.00")
    ->setImageUrl("http://webhsop/product11.jpg")
    ->setDescription("Product11 desc.");

$infoObject->setObject($infoOrderProductItem); //add $infoOrderProductItem to $infoObject
 
$infoOrderProductItem = new \BigFish\PaymentGateway\Data\Info\Order\InfoOrderProductItem();
$infoOrderProductItem->setSku("PMG055008")
    ->setName("Product12")
    ->setQuantity("10")
    ->setQuantityUnit("db")
    ->setUnitPrice("22.00")
    ->setImageUrl("http://webhsop/product12.jpg")
    ->setDescription("Product12 desc.");

$infoObject->setObject($infoOrderProductItem); //add $infoOrderProductItem to $infoObject

初始化

...
    $init->setInfo($infoObject);
...

支付

...
    $payout->setInfo($infoObject);
...

InitRP

...
    $initRP->setInfo($infoObject);
...

支付链接

...
    $paymentLink->setInfo($infoObject);
...