This repository was archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreatePaymentRequest.php
91 lines (78 loc) · 2.41 KB
/
createPaymentRequest.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
<?php
/**
* Paypa Plane sample php script to create a payment request
*
* Log into https://staging-admin.paypaplane.com to acquire the following details
*/
// Create a token at staging-admin.paypaplane.com under Account -> Api Keys [mandatory]
define('TOKEN', '');
// The site guid can be found under Account -> Sites, click "manage" on the site, scroll down till you see GUID [mandatory]
define('SITE_ID', '');
// The account id can be found under Account -> Details, "Account ID" field [mandatory]
define('ACCOUNT_ID', '');
function createPaymentRequest($data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://staging-api.paypaplane.com/v1.0/payment-requests');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = 'Authorization: Bearer ' . TOKEN;
$headers[] = 'Cache-Control: no-cache';
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
return json_decode($result, true);
}
// See documentation for details about payment request fields
// Documentation is available at https://dev-developers.paypaplane.com/
$baseMetadata = [
'type' => 'description',
'data' => [
'description' => 'Membership Fees'
]
];
$stages = [[
'frequency' => 2,
'period' => 'Week',
'duration' => 0,
'description' => 'Fortnightly Payment',
'amount' => 50,
'withdrawDay' => 'sale'
]];
$req = [
'accountId' => ACCOUNT_ID,
'siteId' => SITE_ID,
'amount' => [
'amount' => 0,
'currency' => 'AUD'
],
// 'isRecurring' => true,
'recurrence' => [
'startDate' => '2019-06-16T10:00:00Z',
'stages' => [],
'backdate' => true,
'minimumDaysUntilFirstPayment' => 0
],
'transactionTypes' => ['visa', 'mastercard', 'amex', 'btau_credit'],
'lead' => [
'email' => '',
'mobile' => '0400111222',
'name' => 'New Members Name',
'sendSms' => false
]
];
$req['recurrence']['stages'] = $stages;
$req['metadata'] = $baseMetadata;
$req['reference'] = '';
$res = createPaymentRequest($req);
if (is_array($res) && isset($res['id'])) {
echo "\nSuccess " . $req['lead']['name'] . ' => ' . $res['id']."\n";
} else {
echo "\nERROR " . $req['lead']['name'] . ' => ' . print_r($res)."\n";
}