dagar/payu

与PayU重定向支付网关轻松集成

安装: 2

依赖: 0

建议者: 0

安全: 0

星标: 2

关注者: 1

分支: 0

公开问题: 2

类型:composer-package

dev-main 2022-11-29 11:45 UTC

This package is auto-updated.

Last update: 2024-09-25 21:07:10 UTC


README

存在原因

在办公室,我们与几乎所有印度主要支付网关都有合作,因此与支付网关/聚合器的合作已成为我的日常工作。PayU、Razorpay和Stripe在我们的列表中名列前茅。Razorpay和Stripe提供了针对所有主流语言/框架的卓越SDK。

但是,当谈到PayU时,他们似乎并不关心开发工具。

我为此构建了这个项目,以便新手可以了解如何与PayU集成。这样,他们可以在阅读这个存储库的30-40分钟内遵循标准流程并提高生产力。

未来

  • 将逐步添加功能。

注意:具体信息可在问题中找到

功能

- Trigger payu redirect payment with ease.

- Verify Payment Callback/Manually

导入包

use Dagar\PayU\PaymentGateway\Api;

创建类实例

$inst = new Api(
    'KEY', # key provided by Team PayU
    "SECRET", # secret provided by Team PayU
    true # is test mode required
);

设置返回uri路由

$inst->setURI($success_return_uri, $failure_return_uri);

在创建实例后更改参数

$inst->setMerchantKey($string);
$inst->setMerchantSecret($string);
$inst->isProd($bool);

$inst->setProdUri( $string ); 
# https://secure.payu.in/_payment
$inst->setTestUri( $string ); 
# https://test.payu.in/_payment

$inst->setTestPaymentVerifyUri( $string ); 
# https://test.payu.in/merchant/postservice.php?form=2
$inst->setProdPaymentVerifyUri( $string ); 
# https://info.payu.in/merchant/postservice.php?form=2

设置费用/折扣

$inst->setDiscount( 10 );
$inst->setFee( 100 );

触发支付

$inst->createOrder(
    $amount ?? 0 , 
    $receipt_No ?? random_int(1,999),
    [
        'name' => 'test', # name of client
        'email' => 'test@test.test', # name of client
        'phone' => '9999999999', # name of client
    ]
); 

验证来自PayU的回调请求

<?php


use Dagar\PayU\PaymentGateway\Api;

// reverse hash checking is always recommended for security reason and discarding invalid requests

$_RECEIVED_TXN_ID = $_POST['txnid'];

//  sensitize and verify that this txnId was send from your system

$inst = new Api(
    'KEY', # key provided by Team PayU
    "SECRET", # secret provided by Team PayU
    true # is test mode required
);

$resp = $inst->verifyPaymentWithTxnID($_RECEIVED_TXN_ID);

$resp['status'] // this is not the status of payment but the api response wether api request got executed correctly or not.

if ($resp['status']==1) {

    $txn_id = $resp['transaction_details'][$_RECEIVED_TXN_ID];
    // get info about transaction here you can get to know a lot about about the transaction it is recommended that you keep this response on your server somewhere

    $txn_id['net_amount_debit'];
    // this will tell you how much about was paid by the end customer

    $txn_id['status'] ?? $txn_id['unmappedstatus'];
    //  these will tell you payment was a success or not # remember to check for both

    //  update payment status

}

?>