php-junior/laravel-2c2p

2C2P 支付网关 API & 123 API

1.2 2017-09-13 01:46 UTC

This package is auto-updated.

Last update: 2024-09-07 17:30:31 UTC


README

StyleCI Latest Stable Version Total Downloads

Laravel 2C2P 包

Laravel 版本 5.x.x

安装

使用 composer 安装

composer require php-junior/laravel-2c2p

Laravel 5.5 使用包自动发现,因此不需要您手动添加 ServiceProvider。

如果您不使用自动发现,请将 ServiceProvider 添加到 config/app.php 文件中的 providers 数组

PhpJunior\Laravel2C2P\Laravel2C2PServiceProvider::class,

并且

php artisan vendor:publish --provider="PhpJunior\Laravel2C2P\Laravel2C2PServiceProvider" --force

这是已发布配置文件的内容

return [
    'merchant_id' => 'JT01',
    'secret_key' => '7jYcp4FxFdf0',

    'private_key_pass' => '2c2p',
    'private_key_path' => storage_path('cert/private.pem'),
    'public_key_path' => storage_path('cert/public.crt'),

    'redirect_access_url' => 'https://demo2.2c2p.com/2C2PFrontEnd/RedirectV3/payment',

    'access_url' => 'https://demo2.2c2p.com/2C2PFrontEnd/SecurePayment/PaymentAuth.aspx',
    'secure_pay_script' => 'https://demo2.2c2p.com/2C2PFrontEnd/SecurePayment/api/my2c2p.1.6.9.min.js',

    'currency_code' => 702, // Ref: http://en.wikipedia.org/wiki/ISO_4217
    'country_code' => 'MMR',

    '123_merchant_id' => 'merchant@smarthotel.com',
    '123_api_secret_key' => 'M5WCTP59J544IRRUBTJE0Q7Z2PAJX3CT',
    '123_public_key_path' => storage_path('cert/123.pem'), // 123' Certificate file
    '123_currency_code' => 'MMK',
    '123_country_code' => 'MMR',
    '123_agent_code' => 'ABC',
    '123_channel_code' => 'OVERTHECOUNTER',
    '123_merchant_url' => 'merchant url',
    '123_api_call_url' => 'api call url',
    '123_access_url' => 'https://demo3.2c2p.com/123MM/Payment/Pay/Slip'

    //QuickPay 
    'direct_api' => 'http://demo2.2c2p.com/2C2PFrontEnd/QuickPay/DirectAPI',
    'delivery_api' => 'http://demo2.2c2p.com/2C2PFrontEnd/QuickPay/DeliveryAPI'
];

支付请求 [使用支付网关 API 和 SecurePay]

构建支付表单

data-encrypt 字段添加到表单中,以安全地捕获卡信息。

<form id="2c2p-payment-form" action="" method="POST">
    <input type="text" data-encrypt="cardnumber" maxlength="16" placeholder="Credit Card Number"><br/>
    <input type="text" data-encrypt="month" maxlength="2" placeholder="MM"><br/>
    <input type="text" data-encrypt="year" maxlength="4" placeholder="YYYY"><br/>
    <input type="password" data-encrypt="cvv" maxlength="4" autocomplete="off" placeholder="CVV2/CVC2" ><br/>
    <input type="submit" value="Submit">
</form>

<script type="text/javascript" src="{{ config('laravel-2c2p.secure_pay_script') }}"></script>
<script type="text/javascript">
    My2c2p.onSubmitForm("2c2p-payment-form", function(errCode,errDesc){
        if(errCode!=0){ 
            alert(errDesc);
        }
    });
</script>

提交请求后,您的后端代码将从结算页面接收加密的信用卡详细信息

准备
$payload = \Payment2C2P::paymentRequest([
         'desc' => '1 room for 2 nights',
         'uniqueTransactionCode' => "Invoice".time(),
         'amt' => '1000000',
         'currencyCode' => '702',
         'cardholderName' => 'Card holder Name',
         'cardholderEmail' => 'email@emailcom',
         'panCountry' => 'SG',
         'encCardData' => $request->input('encryptedCardInfo'), // Retrieve encrypted credit card data 
         'userDefined1' => 'userDefined1',
         'userDefined2' => 'userDefined2'
     ]);

提交支付请求

<!-- POST method to submit the form -->
<form action='{{ config('laravel-2c2p.access_url') }}' method='POST' name='paymentRequestForm'>
    Processing payment request, Do not close the browser, press back or refresh the page.
    <input type="hidden" name="paymentRequest" value="{{ $payload }}">
</form>
<script language="JavaScript">
    document.paymentRequestForm.submit();
</script>

处理响应

   $response = \Payment2C2P::getData($request->get('paymentResponse'))
   
   dd($response)

支付请求 [使用 123 API]

$onwTwoThreeReq = \Payment2C2P::OneTwoThreeRequest([
       'MessageID' => '222222',
       'InvoiceNo' => 'QW232142',
       'Amount'    => 24444,
       'Discount'    => 10,
       'ShippingFee'    => 10,
       'ServiceFee'    => 10,
       'ProductDesc' => '1 room for 2 nights',
       'PayerName' => 'Name',
       'PayerEmail' => 'email@email.com',
       'ShippingAddress' => 'Yangon',
       'PayInSlipInfo' => 'Hello World',
       'PaymentItems' => [
           [
               'id' => 1212,
               'name' => 'Bla Bla',
               'price' => 12222,
               'quantity' => 1
           ],
           [
               'id' => 12,
               'name' => 'Bla Bla#2',
               'price' => 12222,
               'quantity' => 1
           ]
       ]
   ]);

提交支付请求

<!-- POST method to submit the form -->
<form action='{{ config('laravel-2c2p.123_access_url') }}' method='POST' name='paymentRequestForm'>
    Processing payment request, Do not close the browser, press back or refresh the page.
    <input type="hidden" name="OneTwoThreeReq" value="{{ $onwTwoThreeReq }}">
</form>
<script language="JavaScript">
    document.paymentRequestForm.submit();
</script>

处理响应

   $response = \Payment2C2P::getData($request->get('OneTwoThreeRes'))
   
   dd($response)

支付请求 [使用重定向 API]

<form action="{{ config('laravel-2c2p.redirect_access_url') }}"  method="POST">
    {!! \Payment2C2P::redirectRequest([
            'payment_description' => '2 room 2 night',
            'order_id' => 'QWERZX1234',
            'invoice_no' => 'ZXCQW123',
            'currency' => '840',
            'amount' => '1000',
            'customer_email' => 'email@email.com',
            'result_url_1' => 'http://127.0.0.1:8888/payment/complete'
    ]) !!}
    <button type="submit">Submit</button>
</form>

卡支付快速支付

卡支付快速支付提供以下选项

  • 快速支付直接 API - 生成新的快速支付 URL,商户将 URL 传递给客户(即白标)
  • 快速支付交付 API - 生成并发送快速支付 URL 到电子邮件或手机

快速支付请求 [使用直接 API]

    $requestMsg = Payment2C2P::quickPayRequest([
        'orderIdPrefix' => 'QP-zzzz2202',
        'description' => 'asasas',
        'currency' => 'USD',
        'amount' => '10',
        'allowMultiplePayment' => 'N',
        'expiry' => '16092017',
        'resultUrl1' => 'http://61.91.121.190/2c2pfrontend/uat/demomerchant/v3uifrontendurl.aspx', //	Front end return URL
        'resultUrl2' => 'http://61.91.121.190/2c2pfrontend/uat/demomerchant/v3uibackendurl.aspx',  //	Back end return URL
    ], 'generate' );

     $curl = curl_init();
     curl_setopt_array($curl, array(
       CURLOPT_URL => config('laravel-2c2p.direct_api'),
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_POSTFIELDS => $requestMsg,
     ));

     $response = curl_exec($curl);
     $err = curl_error($curl);
    
     curl_close($curl);
    
     if ($err) {
       dd("cURL Error #:" . $err);
     } else {
       dd(base64_decode($response)) ;
     }

快速支付请求 [使用交付 API]

    $requestMsg = Payment2C2P::quickPayRequest([
        'orderIdPrefix' => 'QP-zzzz2202',
        'description' => 'asasas',
        'currency' => 'USD',
        'amount' => '10',
        'allowMultiplePayment' => 'N',
        'expiry' => '16092017',
        'resultUrl1' => 'http://61.91.121.190/2c2pfrontend/uat/demomerchant/v3uifrontendurl.aspx', //	Front end return URL
        'resultUrl2' => 'http://61.91.121.190/2c2pfrontend/uat/demomerchant/v3uibackendurl.aspx',  //	Back end return URL
        'toEmails' => 'email@email.com',
        'emailSubject' => 'Email Subject',
        'emailMessage' => 'Message'
    ], 'generate-send' );

     $curl = curl_init();
     curl_setopt_array($curl, array(
       CURLOPT_URL => config('laravel-2c2p.delivery_api'),
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_POSTFIELDS => $requestMsg,
     ));

     $response = curl_exec($curl);
     $err = curl_error($curl);
    
     curl_close($curl);
    
     if ($err) {
       dd("cURL Error #:" . $err);
     } else {
       dd(base64_decode($response)) ;
     }

将现有的快速支付 URL 发送到电子邮件或手机。

    $requestMsg = Payment2C2P::quickPayRequest([
        'qpID' => '121212',
        'toEmails' => 'email@email.com',
        'emailSubject' => 'Email Subject',
        'emailMessage' => 'Message'
    ], 'send-url' );

     $curl = curl_init();
     curl_setopt_array($curl, array(
       CURLOPT_URL => config('laravel-2c2p.delivery_api'),
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_POSTFIELDS => $requestMsg,
     ));

     $response = curl_exec($curl);
     $err = curl_error($curl);
    
     curl_close($curl);
    
     if ($err) {
       dd("cURL Error #:" . $err);
     } else {
       dd(base64_decode($response)) ;
     }

快速支付查询 - 允许检查现有快速支付交易的状态

    $requestMsg = Payment2C2P::quickPayRequest([
        'qpID' => '12122',
    ], 'check' );

     $curl = curl_init();
     curl_setopt_array($curl, array(
       CURLOPT_URL => config('laravel-2c2p.direct_api'),
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_POSTFIELDS => $requestMsg,
     ));

     $response = curl_exec($curl);
     $err = curl_error($curl);
    
     curl_close($curl);
    
     if ($err) {
       dd("cURL Error #:" . $err);
     } else {
       dd(base64_decode($response)) ;
     }

快速支付更新 - 允许修改现有快速支付交易

    $requestMsg = Payment2C2P::quickPayRequest([
        'qpID' => '1212',
        'description' => 'asasas',
        'currency' => 'USD',
        'amount' => '10',
    ], 'update' );

     $curl = curl_init();
     curl_setopt_array($curl, array(
       CURLOPT_URL => config('laravel-2c2p.direct_api'),
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_POSTFIELDS => $requestMsg,
     ));

     $response = curl_exec($curl);
     $err = curl_error($curl);
    
     curl_close($curl);
    
     if ($err) {
       dd("cURL Error #:" . $err);
     } else {
       dd(base64_decode($response)) ;
     }

快速支付删除 - 允许删除现有快速支付交易

    $requestMsg = Payment2C2P::quickPayRequest([
        'qpID' => '121212',
    ], 'delete' );

     $curl = curl_init();
     curl_setopt_array($curl, array(
       CURLOPT_URL => config('laravel-2c2p.direct_api'),
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_POSTFIELDS => $requestMsg,
     ));

     $response = curl_exec($curl);
     $err = curl_error($curl);
    
     curl_close($curl);
    
     if ($err) {
       dd("cURL Error #:" . $err);
     } else {
       dd(base64_decode($response)) ;
     }

API 变量

  • 重定向 API 变量请参考 这里
  • 支付网关 API 变量请参考 这里
  • 123 API 请参考 这里
  • 快速支付变量请参考 这里

完整文档

阅读完整文档 这里

许可

MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。

在 Beerpay 上寻求支持

嘿兄弟!帮我点一杯 🍻!

Beerpay Beerpay