PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / vendor / paypal / paypal-checkout-sdk / samples / ErrorSample.php

ErrorSample.php in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at vendor/paypal/paypal-checkout-sdk/samples/ErrorSample.php

95 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 require __DIR__ . '/../vendor/autoload.php';
4
5 use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
6 use Sample\PayPalClient;
7 use PayPalHttp\HttpException;
8
9 class ErrorSample
10 {
11 public static function prettyPrint($jsonData, $pre="")
12 {
13 $pretty = "";
14 foreach ($jsonData as $key => $val)
15 {
16 $pretty .= $pre . ucfirst($key) .": ";
17 if (strcmp(gettype($val), "array") == 0){
18 $pretty .= "\n";
19 $sno = 1;
20 foreach ($val as $value)
21 {
22 $pretty .= $pre . "\t" . $sno++ . ":\n";
23 $pretty .= self::prettyPrint($value, $pre . "\t\t");
24 }
25 }
26 else {
27 $pretty .= $val . "\n";
28 }
29 }
30 return $pretty;
31 }
32
33 /**
34 * Body has no required parameters (intent, purchase_units)
35 */
36 public static function createError1()
37 {
38 $request = new OrdersCreateRequest();
39 $request->body = "{}";
40 print "Request Body: {}\n\n";
41
42 print "Response:\n";
43 try{
44 $client = PayPalClient::client();
45 $response = $client->execute($request);
46 }
47 catch(HttpException $exception){
48 $message = json_decode($exception->getMessage(), true);
49 print "Status Code: {$exception->statusCode}\n";
50 print(self::prettyPrint($message));
51 }
52 }
53
54 /**
55 * Body has invalid parameter value for intent
56 */
57 public static function createError2()
58 {
59 $request = new OrdersCreateRequest();
60 $request->body = array (
61 'intent' => 'INVALID',
62 'purchase_units' =>
63 array (
64 0 =>
65 array (
66 'amount' =>
67 array (
68 'currency_code' => 'USD',
69 'value' => '100.00',
70 ),
71 ),
72 ),
73 );
74 print "Request Body:\n" . json_encode($request->body, JSON_PRETTY_PRINT) . "\n\n";
75
76 try{
77 $client = PayPalClient::client();
78 $response = $client->execute($request);
79 }
80 catch(HttpException $exception){
81 print "Response:\n";
82 $message = json_decode($exception->getMessage(), true);
83 print "Status Code: {$exception->statusCode}\n";
84 print(self::prettyPrint($message));
85 }
86
87 }
88 }
89
90 print "Calling createError1 (Body has no required parameters (intent, purchase_units))\n";
91 ErrorSample::createError1();
92
93 print "\n\nCalling createError2 (Body has invalid parameter value for intent)\n";
94 ErrorSample::createError2();
95