-
Notifications
You must be signed in to change notification settings - Fork 34
/
CreatePayoutSample.php
executable file
·73 lines (67 loc) · 2.04 KB
/
CreatePayoutSample.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
<?php
namespace Sample;
require __DIR__ . '/../vendor/autoload.php';
use Sample\PayPalClient;
use PaypalPayoutsSDK\Payouts\PayoutsPostRequest;
use PayPalHttp\HttpException;
class CreatePayoutSample
{
public static function buildRequestBody()
{
return json_decode(
'{
"sender_batch_header":
{
"email_subject": "SDK payouts test txn"
},
"items": [
{
"recipient_type": "EMAIL",
"receiver": "payouts2342@paypal.com",
"note": "Your 1$ payout",
"sender_item_id": "Test_txn_12",
"amount":
{
"currency": "USD",
"value": "1"
}
}]
}',
true
);
}
/**
* This function can be used to create payout.
*/
public static function CreatePayout($debug = false)
{
try {
$request = new PayoutsPostRequest();
$request->body = self::buildRequestBody();
$client = PayPalClient::client();
$response = $client->execute($request);
if ($debug) {
print "Status Code: {$response->statusCode}\n";
print "Status: {$response->result->batch_header->batch_status}\n";
print "Batch ID: {$response->result->batch_header->payout_batch_id}\n";
print "Links:\n";
foreach ($response->result->links as $link) {
print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
}
// To toggle printing the whole response body comment/uncomment below line
echo json_encode($response->result, JSON_PRETTY_PRINT), "\n";
}
return $response;
} catch (HttpException $e) {
//Parse failure response
echo $e->getMessage() . "\n";
$error = json_decode($e->getMessage());
echo $error->message . "\n";
echo $error->name . "\n";
echo $error->debug_id . "\n";
}
}
}
if (!count(debug_backtrace())) {
CreatePayoutSample::CreatePayout(true);
}