PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
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 2.30.0 All 255 releases
give / src / PaymentGateways / PayPalCommerce / PayPalClient.php

PayPalClient.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/PaymentGateways/PayPalCommerce/PayPalClient.php

82 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\PaymentGateways\PayPalCommerce;
4
5 use Give\PaymentGateways\PayPalCommerce\Models\MerchantDetail;
6 use Give\PaymentGateways\PayPalCommerce\Repositories\Traits\HasMode;
7 use PayPalCheckoutSdk\Core\PayPalHttpClient;
8 use PayPalCheckoutSdk\Core\ProductionEnvironment;
9 use PayPalCheckoutSdk\Core\SandboxEnvironment;
10
11 /**
12 * Class PayPalClient
13 *
14 * @package Give\PaymentGateways\PaypalCommerce
15 *
16 * @since 2.9.0
17 */
18 class PayPalClient
19 {
20 use HasMode;
21
22 /**
23 * Get environment.
24 *
25 * @sicne 2.9.0
26 *
27 * @return ProductionEnvironment|SandboxEnvironment
28 */
29 public function getEnvironment()
30 {
31 /* @var MerchantDetail $merchant */
32 $merchant = give(MerchantDetail::class);
33
34 return 'sandbox' === $this->mode ?
35 new SandboxEnvironment($merchant->clientId, $merchant->clientSecret) :
36 new ProductionEnvironment($merchant->clientId, $merchant->clientSecret);
37 }
38
39 /**
40 * Get http client.
41 *
42 * @since 2.25.0 Add custom AuthorizationInjector.
43 * @since 2.9.0
44 */
45 public function getHttpClient(): PayPalHttpClient
46 {
47 return new PayPalCheckoutSdk\PayPalHttpClient($this->getEnvironment());
48 }
49
50 /**
51 * Get api url.
52 *
53 * @deprecated 2.30.1
54 * @since 2.9.0
55 *
56 * @param string $endpoint
57 *
58 * @return string
59 */
60 public function getApiUrl($endpoint)
61 {
62 $baseUrl = $this->getEnvironment()->baseUrl();
63
64 return "{$baseUrl}/$endpoint";
65 }
66
67 /**
68 * Get PayPal homepage url.
69 *
70 * @since 2.9.0
71 *
72 * @return string
73 */
74 public function getHomePageUrl()
75 {
76 return sprintf(
77 'https://%1$spaypal.com/',
78 'sandbox' === $this->mode ? 'sandbox.' : ''
79 );
80 }
81 }
82