在Magento 2.2.3中建立自定义支付网关

时间:2018-12-03 05:14:52

标签: php magento2

银行刚给了我2个链接

首先进行令牌验证,如

沙盒网址:somethingurl。

然后我必须通过

{
    "userName":"test",
    "password":"123456Aa"
} 

json格式

此后,我必须从该帖子要求中找到银行生成的令牌。

我已经完成了。

然后我必须将magento 2订单数据(总计)和其他一些凭证发送到银行安全网址:

somethingurl.com/createorder

json格式就是这样

{

"merchantId": "11122333",

"amount": "100",

"currency": "050",

"description": "This is test",

"approveUrl": "http://localhost/TheBankPHP_1.0.1/approve.php",

"cancelUrl": "http://localhost/TheBankPHP_1.0.1/cencel.php",

"declineUrl": "http://localhost/TheBankPHP_1.0.1/decline.php",

"userName": "test",

"passWord": "123456Aa",

"secureToken": "bd6e290e-ca3d-4a4b-b7c1-defe9ff6f7af"

}

现在,我的问题是,当用户单击下订单按钮时​​,该怎么办?并将该订单与该银行订单付款一起存储在我的管理控制台中。

是否可以使用货到付款方式只是设置一个链接。

我已经实现了php页面,但是我不知道如何将其与模块集成。你能帮我@Damian Culotta吗?

下面是我的php文件。

<?php
    $url = "https://sandbox.thebank.com:443/transaction/token";
    $data = json_encode(array("userName" => "test","password" => "123456Aa"));
    $ch = curl_init( $url );
    # Setup request to send json via POST.

    curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
    curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
    # Return response instead of printing.
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    # Send request.
    $result = curl_exec($ch);
    curl_close($ch);
    # Print response.
    echo "<pre>$result</pre>";

    $mydata = json_decode($result, true);

    $sectkn = $mydata["transactionId"];

    echo $sectkn;


    $turl = "https://sandbox.thebank.com:443/transaction/createorder";
    $data = json_encode(array(
    "merchantId" => "11122333",
    "amount" => "100",
    "currency" => "050",
    "description" => "This is test",
    "approveUrl" => "http://localhost/theBankPHP_1.0.1/approve.php",
    "cancelUrl" => "http://localhost/theBankPHP_1.0.1/cencel.php",
    "declineUrl" => "http://localhost/theBankPHP_1.0.1/decline.php",
    "userName" => "test",
    "passWord" => "123456Aa",
    "secureToken" => $sectkn,
    ));
    $ch = curl_init( $turl );
    # Setup request to send json via POST.

    curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
    curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
    # Return response instead of printing.
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    # Send request.
    $tresult = curl_exec($ch);
    curl_close($ch);
    # Print response.
    echo "<pre>$tresult</pre>";



$mydatat = json_decode($tresult, true);

$linkdata = $mydatat["items"];

$myurldata = $linkdata["url"];
$myorder = $linkdata["orderId"];
$mysession = $linkdata["sessionId"];


$redirect_url = $myurldata. "?ORDERID=". $myorder. "&SESSIONID=". $mysession;
header("Location: .$redirect_url");

//echo $redirect_url;

?>

为了安全起见:我更改了银行网址。请帮助我

1 个答案:

答案 0 :(得分:0)

您需要创建自定义模块才能创建自定义支付网关。

我已经为我的需要创建了一个。您可以基于它获得想法。

PayEase Payment Gateway For Magento 2