Help me on Payment Gateway in PHP
I am a trainee web developer, developing a eCommerce site, which need to be linked with payment gateway.
I got the payment gateway details from the bank.
But I don't know how to use the API, what are the parameters should be passed and what will I get back.
Better if I get a sample code set.
have you received the API doc from bank? all the details are in that document, if you share the API document, we can help you
@dev_lak Have you done the dealings with Commercial Bank's Payment gateway..?
This is the integration link they send me. https://test-gateway.mastercard.com/api/documentation/integrationGuidelines/index.html?locale=en_US
@Theesan in this doc, they have 4 checkout models, first decide what is suitable model for you,
- Hosted Checkout
- Hosted Session
- Direct Payment
and then read the relavant integration guid,
and also this doc has some sample codes, see this - https://test-gateway.mastercard.com/api/documentation/downloads/index.html?locale=en_US
root last edited by
you need to use, php curl request to the payment gateway endpoint with required payment method data. that's only. then use request endpoint response to show the errors and success infomation to the end user.
@root I don't know how to use it. Do you have any sample code?
<?php // A sample PHP Script to POST data using cURL // Data in JSON format $data = array( 'username' => 'tecadmin', 'password' => '012345678' ); $payload = json_encode($data); // Prepare new cURL resource $ch = curl_init('https://api.example.com/api/1.0/user/login'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); // Set HTTP Header for POST request curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($payload)) ); // Submit the POST request $result = curl_exec($ch); // Close cURL session handle curl_close($ch); ?>
this is a curl example.