cancel
Showing results for 
Search instead for 
Did you mean: 

Sending session value, Order_id, order_amount, customer_receipt_email in a PHP API from magento2

Sending session value, Order_id, order_amount, customer_receipt_email in a PHP API from magento2

Basically, I've to send my store's order ID, order amount and customer email to a Bank Payment Gateway API. First, please help to figure out how can I send  these data to a external php API (BANK API) to receive last order_id, order_amount from my magento2 store.

2 REPLIES 2

Re: Sending session value, Order_id, order_amount, customer_receipt_email in a PHP API from magento2

You can pass your data to third party service using CURL request with post data in magento 2.

Refer below blogs for pass your data to third party API.

https://www.rakeshjesadiya.com/how-to-use-php-curl-in-magento-2/

 

Thanks.

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

Re: Sending session value, Order_id, order_amount, customer_receipt_email in a PHP API from magento2

Hello @bbbmishucs

You can send external php API on by event after place each order.

Here is overview of creating events in Magento 2

For order, you have create an events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="sales_order_place_after">
        <observer name="send_data_custom_api" instance="VendorName\ModuleName\Observer\Order" />
    </event>
</config>

 

Add below code in observer.php file

 

<?php

class Order implements \Magento\Framework\Event\ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $order = $observer->getEvent()->getOrder();
        echo $orderId = $order->getId();
        // You get all order data here 
    }
}


You get all order data in above function after retrive order data please send to your custom API.

If you have any trouble then let us know.

 

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"