|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Srmklive\PayPal\Traits\PayPalAPI; |
|
4
|
|
|
|
|
5
|
|
|
trait PaymentMethodsTokens |
|
6
|
|
|
{ |
|
7
|
|
|
use PaymentMethodsTokens\Helpers; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Create a payment method token. |
|
11
|
|
|
* |
|
12
|
|
|
* @param array $data |
|
13
|
|
|
* |
|
14
|
|
|
* @throws \Throwable |
|
15
|
|
|
* |
|
16
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
|
17
|
|
|
* |
|
18
|
|
|
* @see https://developer.paypal.com/docs/api/payment-tokens/v3/#payment-tokens_create |
|
19
|
|
|
*/ |
|
20
|
|
|
public function createPaymentSourceToken(array $data) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->apiEndPoint = 'v3/vault/payment-tokens'; |
|
23
|
|
|
|
|
24
|
|
|
$this->options['json'] = $data; |
|
25
|
|
|
|
|
26
|
|
|
$this->verb = 'post'; |
|
27
|
|
|
|
|
28
|
|
|
return $this->doPayPalRequest(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* List all the payment tokens. |
|
33
|
|
|
* |
|
34
|
|
|
* @param int $page |
|
35
|
|
|
* @param int $page_size |
|
36
|
|
|
* @param bool $totals |
|
37
|
|
|
* |
|
38
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
|
39
|
|
|
* |
|
40
|
|
|
* @see https://developer.paypal.com/docs/api/payment-tokens/v3/#customer_payment-tokens_get |
|
41
|
|
|
*/ |
|
42
|
|
|
public function listPaymentSourceTokens(int $page = 1, int $page_size = 10, bool $totals = true) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->apiEndPoint = "v3/vault/payment-tokens?customer_id={$this->customer_source['id']}&page={$page}&page_size={$page_size}&total_required={$totals}"; |
|
45
|
|
|
|
|
46
|
|
|
$this->verb = 'get'; |
|
47
|
|
|
|
|
48
|
|
|
return $this->doPayPalRequest(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Show details for a payment method token. |
|
53
|
|
|
* |
|
54
|
|
|
* @param string $token |
|
55
|
|
|
* |
|
56
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
|
57
|
|
|
* |
|
58
|
|
|
* @see https://developer.paypal.com/docs/api/payment-tokens/v3/#payment-tokens_get |
|
59
|
|
|
*/ |
|
60
|
|
|
public function showPaymentSourceTokenDetails(string $token) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->apiEndPoint = "v3/vault/payment-tokens/{$token}"; |
|
63
|
|
|
|
|
64
|
|
|
$this->verb = 'get'; |
|
65
|
|
|
|
|
66
|
|
|
return $this->doPayPalRequest(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Show details for a payment token. |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $token |
|
73
|
|
|
* |
|
74
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
|
75
|
|
|
* |
|
76
|
|
|
* @see https://developer.paypal.com/docs/api/payment-tokens/v3/#payment-tokens_delete |
|
77
|
|
|
*/ |
|
78
|
|
|
public function deletePaymentSourceToken(string $token) |
|
79
|
|
|
{ |
|
80
|
|
|
$this->apiEndPoint = "v3/vault/payment-tokens/{$token}"; |
|
81
|
|
|
|
|
82
|
|
|
$this->verb = 'delete'; |
|
83
|
|
|
|
|
84
|
|
|
return $this->doPayPalRequest(false); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Create a payment setup token. |
|
89
|
|
|
* |
|
90
|
|
|
* @param array $data |
|
91
|
|
|
* |
|
92
|
|
|
* @throws \Throwable |
|
93
|
|
|
* |
|
94
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
|
95
|
|
|
* |
|
96
|
|
|
* @see https://developer.paypal.com/docs/api/payment-tokens/v3/#setup-tokens_create |
|
97
|
|
|
*/ |
|
98
|
|
|
public function createPaymentSetupToken(array $data) |
|
99
|
|
|
{ |
|
100
|
|
|
$this->apiEndPoint = 'v3/vault/setup-tokens'; |
|
101
|
|
|
|
|
102
|
|
|
$this->options['json'] = $data; |
|
103
|
|
|
|
|
104
|
|
|
$this->verb = 'post'; |
|
105
|
|
|
|
|
106
|
|
|
return $this->doPayPalRequest(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Show details for a payment setup token. |
|
111
|
|
|
* |
|
112
|
|
|
* @param string $token |
|
113
|
|
|
* |
|
114
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
|
115
|
|
|
* |
|
116
|
|
|
* @see https://developer.paypal.com/docs/api/payment-tokens/v3/#setup-tokens_get |
|
117
|
|
|
*/ |
|
118
|
|
|
public function showPaymentSetupTokenDetails(string $token) |
|
119
|
|
|
{ |
|
120
|
|
|
$this->apiEndPoint = "v3/vault/setup-tokens/{$token}"; |
|
121
|
|
|
|
|
122
|
|
|
$this->verb = 'get'; |
|
123
|
|
|
|
|
124
|
|
|
return $this->doPayPalRequest(); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|