Jump to content

Recommended Posts

Good day, I have a pin/token system stored in mysql database for online registration, I also have an online payment system that accepts debit cards. I need a code so as to automatically show a pin to a user who has made payment and also an sms/email carrying the pin/token.
i have a payment page that verifies cards and debits the user called verify.php with code <?php
/**
 * Verify SimplePay transaction
 */

$private_key = 'test_pr_demo';  // put here your private key

// Retrieve data returned in payment gateway callback
$token = $_POST["sp_token"];
$amount = $_POST["sp_amount"];
$amount_currency = $_POST["sp_currency"];
$sp_status = $_POST["sp_status"];
$transaction_id = $_POST["transaction_id"]; // we don't really need this here, is just an example

$data = array(
    'token' => $token,
    'amount' => $amount,
    'amount_currency' => $amount_currency
);
$data_string = json_encode($data);

// Call to charge/verify a payment
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://checkout.simplepay.ng/v2/payments/card/charge/');
curl_setopt($ch, CURLOPT_USERPWD, $private_key . ':');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data_string)
));

$curl_response = curl_exec($ch);
$curl_response = preg_split("/\r\n\r\n/", $curl_response);
$response_content = $curl_response[1];
$json_response = json_decode(chop($response_content), TRUE);
print_r($json_response);
$response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

if ($response_code == '200') {
    // even is http status code is 200 we still need to check transaction had issues or not
    if ($json_response['response_code'] == '20000') {
        // card was successfully charged
        header('Location: success.html');
    } else {
        // failed to charge the card
        header('Location: failed.html');
    }
} else if ($sp_status == 'true') {
    // even though it failed the call to card charge, card payment was already processed
    header('Location: success.html');
} else {
    // failed to charge the card
    header('Location: failed.html');
}
?>

and after, it redirects to success.html. My pins are stored in a database. thank you.

Link to comment
https://forums.phpfreaks.com/topic/302705-please-i-need-help-with-coding/
Share on other sites

You have all this code, so where is the problem? Where is the code to do this thing you are asking about? Do you want us to write it for you?

 

Show us the code that is not working and perhaps someone will help you over that hurdle.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.