cancel
Showing results for 
Search instead for 
Did you mean: 

Send order amount to a external link (like BANK API URL) ?

Send order amount to a external link (like BANK API URL) ?

how can I get send grand total in Magento 2 checkout page before click on the place order button and send it to my 3rd party API url?

4 REPLIES 4

Re: Send order amount to a external link (like BANK API URL) ?

You can send amount to the third party via api using before event of place order.

 

You can check event list from Get list of events in Magento 2

You need to create event observer for solved your an issue.

Use sales_model_service_quote_submit_before for request API url.

 

 

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Send order amount to a external link (like BANK API URL) ?

Thank you for your nice reply.

Bank just gave me 2 links

first for token validation like.

sandbox url: somethingurl.

then I have to pass

{

    "userName":"test",

    "password":"123456Aa"

  } in json format

after that I have to find bank generated token from this post reguest.

which I've already done.

and then I've to send magento 2 order data (grand total) with some other credentials to a bank secure url:

somethingurl.com/createorder 

json format is like this

 

{

"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"

}

 

Now, my question is how can I do this when user click place order button. and store that in my admin panel that order is placed with that bank order payment.

Is it possible to use cash on delivery method just set a link.

 

I've implemented a php page but how I integrate this with a module I've no idea. Can you please help me @Rakesh Jesadiya

 

here is my php file given below.

<?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. for security purpose: I've changed the bank url. please help me @Rakesh Jesadiya

Re: Send order amount to a external link (like BANK API URL) ?

 

You have to create event observer for send data to third party

check link, https://magento.stackexchange.com/questions/179633/magento2-how-create-an-observer

 

You need to send data using observer after place order using my old post's mentioned event.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Send order amount to a external link (like BANK API URL) ?

Hi @bbbmishucs,

You just create this event observer for after place order
Use this event observer sales_order_place_after for creating the events after place order

If my solution is helpful, give kudos and accept as solution
Best regards
Madhuresan
Bootsgrid