srmklive /
laravel-paypal
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Srmklive\PayPal\Traits\PayPalAPI; |
||
| 4 | |||
| 5 | trait Identity |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Get user profile information. |
||
| 9 | * |
||
| 10 | * @throws \Throwable |
||
| 11 | * |
||
| 12 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 13 | * |
||
| 14 | * @see https://developer.paypal.com/docs/api/identity/v1/#userinfo_get |
||
| 15 | */ |
||
| 16 | public function showProfileInfo() |
||
| 17 | { |
||
| 18 | $this->apiEndPoint = 'v1/identity/openidconnect/userinfo?schema=openid'; |
||
| 19 | |||
| 20 | $this->setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 21 | |||
| 22 | $this->verb = 'get'; |
||
| 23 | |||
| 24 | return $this->doPayPalRequest(); |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * List Users. |
||
| 29 | * |
||
| 30 | * @param string $field |
||
| 31 | * |
||
| 32 | * @throws \Throwable |
||
| 33 | * |
||
| 34 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 35 | * |
||
| 36 | * @see https://developer.paypal.com/docs/api/identity/v2/#users_list |
||
| 37 | */ |
||
| 38 | public function listUsers(string $field = 'userName') |
||
| 39 | { |
||
| 40 | $this->apiEndPoint = "v2/scim/Users?filter={$field}"; |
||
| 41 | |||
| 42 | $this->setRequestHeader('Content-Type', 'application/scim+json'); |
||
| 43 | |||
| 44 | $this->verb = 'get'; |
||
| 45 | |||
| 46 | return $this->doPayPalRequest(); |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Show details for a user by ID. |
||
| 51 | * |
||
| 52 | * @param string $user_id |
||
| 53 | * |
||
| 54 | * @throws \Throwable |
||
| 55 | * |
||
| 56 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 57 | * |
||
| 58 | * @see https://developer.paypal.com/docs/api/identity/v2/#users_get |
||
| 59 | */ |
||
| 60 | public function showUserDetails(string $user_id) |
||
| 61 | { |
||
| 62 | $this->apiEndPoint = "v2/scim/Users/{$user_id}"; |
||
| 63 | |||
| 64 | $this->setRequestHeader('Content-Type', 'application/scim+json'); |
||
| 65 | |||
| 66 | $this->verb = 'get'; |
||
| 67 | |||
| 68 | return $this->doPayPalRequest(); |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Delete a user by ID. |
||
| 73 | * |
||
| 74 | * @param string $user_id |
||
| 75 | * |
||
| 76 | * @throws \Throwable |
||
| 77 | * |
||
| 78 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 79 | * |
||
| 80 | * @see https://developer.paypal.com/docs/api/identity/v2/#users_get |
||
| 81 | */ |
||
| 82 | public function deleteUser(string $user_id) |
||
| 83 | { |
||
| 84 | $this->apiEndPoint = "v2/scim/Users/{$user_id}"; |
||
| 85 | |||
| 86 | $this->setRequestHeader('Content-Type', 'application/scim+json'); |
||
| 87 | |||
| 88 | $this->verb = 'delete'; |
||
| 89 | |||
| 90 | return $this->doPayPalRequest(false); |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Create a merchant application. |
||
| 95 | * |
||
| 96 | * @param string $client_name |
||
| 97 | * @param array $redirect_uris |
||
| 98 | * @param array $contacts |
||
| 99 | * @param string $payer_id |
||
| 100 | * @param string $migrated_app |
||
| 101 | * @param string $application_type |
||
| 102 | * @param string $logo_url |
||
| 103 | * |
||
| 104 | * @throws \Throwable |
||
| 105 | * |
||
| 106 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 107 | * |
||
| 108 | * @see https://developer.paypal.com/docs/api/identity/v1/#applications_post |
||
| 109 | */ |
||
| 110 | public function createMerchantApplication(string $client_name, array $redirect_uris, array $contacts, string $payer_id, string $migrated_app, string $application_type = 'web', string $logo_url = '') |
||
| 111 | { |
||
| 112 | $this->apiEndPoint = 'v1/identity/applications'; |
||
| 113 | |||
| 114 | $this->options['json'] = array_filter([ |
||
| 115 | 'application_type' => $application_type, |
||
| 116 | 'redirect_uris' => $redirect_uris, |
||
| 117 | 'client_name' => $client_name, |
||
| 118 | 'contacts' => $contacts, |
||
| 119 | 'payer_id' => $payer_id, |
||
| 120 | 'migrated_app' => $migrated_app, |
||
| 121 | 'logo_uri' => $logo_url, |
||
| 122 | ]); |
||
| 123 | |||
| 124 | $this->verb = 'post'; |
||
| 125 | |||
| 126 | return $this->doPayPalRequest(); |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Create a merchant application. |
||
| 131 | * |
||
| 132 | * @param array $features |
||
| 133 | * @param string $account_property |
||
| 134 | * |
||
| 135 | * @throws \Throwable |
||
| 136 | * |
||
| 137 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 138 | * |
||
| 139 | * @see https://developer.paypal.com/docs/api/identity/v1/#account-settings_post |
||
| 140 | */ |
||
| 141 | public function setAccountProperties(array $features, string $account_property = 'BRAINTREE_MERCHANT') |
||
| 142 | { |
||
| 143 | $this->apiEndPoint = 'v1/identity/account-settings'; |
||
| 144 | |||
| 145 | $this->options['json'] = [ |
||
| 146 | 'account_property' => $account_property, |
||
| 147 | 'features' => $features, |
||
| 148 | ]; |
||
| 149 | |||
| 150 | $this->verb = 'post'; |
||
| 151 | |||
| 152 | return $this->doPayPalRequest(); |
||
| 153 | } |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Create a merchant application. |
||
| 157 | * |
||
| 158 | * @param string $account_property |
||
| 159 | * |
||
| 160 | * @throws \Throwable |
||
| 161 | * |
||
| 162 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 163 | * |
||
| 164 | * @see https://developer.paypal.com/docs/api/identity/v1/#account-settings_deactivate |
||
| 165 | */ |
||
| 166 | public function disableAccountProperties(string $account_property = 'BRAINTREE_MERCHANT') |
||
| 167 | { |
||
| 168 | $this->apiEndPoint = 'v1/identity/account-settings/deactivate'; |
||
| 169 | |||
| 170 | $this->options['json'] = [ |
||
| 171 | 'account_property' => $account_property, |
||
| 172 | ]; |
||
| 173 | |||
| 174 | $this->verb = 'post'; |
||
| 175 | |||
| 176 | return $this->doPayPalRequest(); |
||
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Get a client token. |
||
| 181 | * |
||
| 182 | * @throws \Throwable |
||
| 183 | * |
||
| 184 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
| 185 | * |
||
| 186 | * @see https://developer.paypal.com/docs/multiparty/checkout/advanced/integrate/#link-sampleclienttokenrequest |
||
| 187 | */ |
||
| 188 | public function getClientToken() |
||
| 189 | { |
||
| 190 | $this->apiEndPoint = 'v1/identity/generate-token'; |
||
| 191 | |||
| 192 | $this->verb = 'post'; |
||
| 193 | |||
| 194 | return $this->doPayPalRequest(); |
||
| 195 | } |
||
| 196 | } |
||
| 197 |