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

Build a custom payment gateway in Magento 2.2.3

银行刚给了我 2 links

首先进行令牌验证。

沙盒url:某事url。

那我得通过

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

json格式

之后我必须从这个 post 请求中找到银行生成的令牌。

我已经完成了。

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

某事url.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"

}

现在,我的问题是当用户单击“下订单”按钮时我该如何执行此操作。并将其存储在我的管理面板中,该订单是通过该银行订单付款下达的。

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

我已经实现了一个 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;

?>

N.B。出于安全目的:我已经更改了银行 url。请帮助我

您需要创建自定义模块来创建您的自定义支付网关。

我已经根据需要创建了一个。你可以根据它得到想法。

PayEase Payment Gateway For Magento 2