- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Magento 2 Blogs/Tutorial
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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"