-
Notifications
You must be signed in to change notification settings - Fork 3
/
disbursements.php
92 lines (73 loc) · 2.3 KB
/
disbursements.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
require_once 'vendor/autoload.php';
require_once 'Authorisation.php';
use GuzzleHttp\Client;
/*
RSA PASSWORD ENCRYPTION WITH PADDING OPENSSL_PKCS1_PADDING 1024
BITS 64BIT ENCODED
*/
//Type of padding
$padding = OPENSSL_PKCS1_PADDING;
//4 digit Pin from Customer/Client
$sensitiveData = '1111';
// Get keys from a string. Public key for encrypting from the Documentation
$publicKeyString = <<<'PK'
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCkq3XbDI1s8Lu7SpUBP+bqOs/MC6PKWz6n/0UkqTiOZqKqaoZClI3BUDTrSIJsrN1Qx7ivBzsaAYfsB0CygSSWay4iyUcnMVEDrNVOJwtWvHxpyWJC5RfKBrweW9b8klFa/CfKRtkK730apy0Kxjg+7fF0tB4O3Ic9Gxuv4pFkbQIDAQAB
-----END PUBLIC KEY-----
PK;
// Load public key
$publicKey = openssl_pkey_get_public([$publicKeyString, '']);
if (!$publicKey) {
echo 'Public key NOT Correct
';
}
if (!openssl_public_encrypt($sensitiveData, $encryptedWithPublic, $publicKey, $padding)) {
echo 'Error encrypting with public key
';
}
//Encrypted Pin
$pinEncrypted = base64_encode($encryptedWithPublic);
//
/*
This API is used to request a payment from a consumer(Payer).
The consumer(payer) will be asked to authorize the payment.
After authorization, the transaction will be executed.
*/
$client = new Client();
//Enter phone number here without the country code
$phone_number = '97***12';
//Country Code
$country_code = 'ZM';
//Currency Code
$currency_code = 'ZMW';
//Amount to be sent
$amount = '1';
//Check for errors while executing the code
try {
$response = $client->request('POST', 'https://openapiuat.airtel.africa/standard/v1/disbursements/', [
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer '.$access_token,
'X-Country' => "$country_code",
'X-Currency' => "$currency_code",
],
'json'=> [
'payee' => [
'msisdn' => $phone_number,
],
'reference' => 'Disbursements',
'pin' => "$pinEncrypted",
'transaction' => [
'amount' => $amount,
'id' => mt_rand(1000000, 9999999),
],
],
]);
$push_payments = $response->getBody();
echo $push_payments;
}
//Throw Error Here
catch (Exception $e) {
echo 'Whoops something went wrong: '.$e->getMessage();
}