Попытка выяснить, как взаимодействовать с PayGate API - PullRequest
0 голосов
/ 26 апреля 2020

Я вижу, что эти параметры требуются, когда я вызываю API платежного шлюза, но я не знаю, как бы это реализовать в Javascript (в частности, React). Любые переводчики могут протянуть руку?

Вот пример кода в PHP:

$encryptionKey = 'secret';

$DateTime = new DateTime();

$data = array(
    'PAYGATE_ID'        => 10011072130,
    'REFERENCE'         => 'pgtest_123456789',
    'AMOUNT'            => 3299,
    'CURRENCY'          => 'ZAR',
    'RETURN_URL'        => 'https://my.return.url/page',
    'TRANSACTION_DATE'  => $DateTime->format('Y-m-d H:i:s'),
    'LOCALE'            => 'en-za',
    'COUNTRY'           => 'ZAF',
    'EMAIL'             => 'customer@paygate.co.za',
);

$checksum = md5(implode('', $data) . $encryptionKey);

$data['CHECKSUM'] = $checksum;

$fieldsString = http_build_query($data);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, 'https://secure.paygate.co.za/payweb3/initiate.trans');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['HTTP_HOST']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsString);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

Я пытался использовать топор ios, чтобы сделать запрос, но любой метод будет делать. Я пытался создать экземпляр топора ios примерно так:


export default axios.create({
    baseURL: 'https://secure.paygate.co.za/payweb3/initiate.trans',
    headers:{
      //I guess this is where PAYGATE_ID etc would go, but I'm not sure how to format it
    }
})```
...