Traits
4 years ago
MerchantDetails.php
4 years ago
PayPalAuth.php
3 years ago
PayPalOrder.php
4 years ago
Settings.php
3 years ago
Webhooks.php
4 years ago
Settings.php
202 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\PayPalCommerce\Repositories; |
| 4 | |
| 5 | use Give\PaymentGateways\PayPalCommerce\Models\MerchantDetail; |
| 6 | |
| 7 | class Settings |
| 8 | { |
| 9 | /** |
| 10 | * wp_options key for the account country |
| 11 | * |
| 12 | * @since 2.9.0 |
| 13 | */ |
| 14 | const COUNTRY_KEY = 'paypal_commerce_account_country'; |
| 15 | |
| 16 | /** |
| 17 | * wp_options key for the seller access token |
| 18 | * |
| 19 | * @since 2.9.0 |
| 20 | */ |
| 21 | const ACCESS_TOKEN_KEY = 'temp_give_paypal_commerce_seller_access_token'; |
| 22 | |
| 23 | /** |
| 24 | * wp_options key for the partner link details |
| 25 | * |
| 26 | * @since 2.9.0 |
| 27 | */ |
| 28 | const PARTNER_LINK_DETAIL_KEY = 'temp_give_paypal_commerce_partner_link'; |
| 29 | |
| 30 | /** |
| 31 | * give_settings key for the collect bulling details |
| 32 | * |
| 33 | * @since 2.11.1 |
| 34 | */ |
| 35 | const COLLECT_BILLING_DETAILS_KEY = 'paypal_commerce_collect_billing_details'; |
| 36 | |
| 37 | /** |
| 38 | * give_settings key for the collect bulling details |
| 39 | * |
| 40 | * @since 2.16.2 |
| 41 | */ |
| 42 | const TRANSACTION_TYPE = 'paypal_commerce_transaction_type'; |
| 43 | |
| 44 | /** |
| 45 | * Returns the country for the account |
| 46 | * |
| 47 | * @since 2.9.0 |
| 48 | * |
| 49 | * @return string|null |
| 50 | */ |
| 51 | public function getAccountCountry() |
| 52 | { |
| 53 | return get_option(self::COUNTRY_KEY, give_get_country()); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns the PayPal merchant seller access token. |
| 58 | * |
| 59 | * @since 2.9.0 |
| 60 | * |
| 61 | * @return array|null |
| 62 | */ |
| 63 | public function getAccessToken() |
| 64 | { |
| 65 | return get_option(self::ACCESS_TOKEN_KEY, null); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Returns the account access token |
| 70 | * |
| 71 | * @since 2.9.0 |
| 72 | * |
| 73 | * @return array|null |
| 74 | */ |
| 75 | public function getTransactionType() |
| 76 | { |
| 77 | return give_get_option(self::TRANSACTION_TYPE, 'donation'); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Updates the country account |
| 82 | * |
| 83 | * @param string $country |
| 84 | * |
| 85 | * @return bool |
| 86 | */ |
| 87 | public function updateAccountCountry($country) |
| 88 | { |
| 89 | return update_option(self::COUNTRY_KEY, $country); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Updates the PayPal merchant seller access token. |
| 94 | * |
| 95 | * @param $token |
| 96 | * |
| 97 | * @return bool |
| 98 | */ |
| 99 | public function updateAccessToken($token) |
| 100 | { |
| 101 | return update_option(self::ACCESS_TOKEN_KEY, $token); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Deletes the PayPal seller access token. |
| 106 | * |
| 107 | * @since 2.9.0 |
| 108 | * |
| 109 | * @return bool |
| 110 | */ |
| 111 | public function deleteAccessToken() |
| 112 | { |
| 113 | return delete_option(self::ACCESS_TOKEN_KEY); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Returns the partner link details |
| 118 | * |
| 119 | * @since 2.9.0 |
| 120 | * |
| 121 | * @return string|null |
| 122 | */ |
| 123 | public function getPartnerLinkDetails() |
| 124 | { |
| 125 | return get_option(self::PARTNER_LINK_DETAIL_KEY, null); |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Updates the partner link details |
| 130 | * |
| 131 | * @param $linkDetails |
| 132 | * |
| 133 | * @return bool |
| 134 | */ |
| 135 | public function updatePartnerLinkDetails($linkDetails) |
| 136 | { |
| 137 | return update_option(self::PARTNER_LINK_DETAIL_KEY, $linkDetails); |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Deletes the partner link details |
| 142 | * |
| 143 | * @return bool |
| 144 | */ |
| 145 | public function deletePartnerLinkDetails() |
| 146 | { |
| 147 | return delete_option(self::PARTNER_LINK_DETAIL_KEY); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Updates the partner link details |
| 152 | * |
| 153 | * @since 2.25.0 |
| 154 | */ |
| 155 | public function updateSellerAccessToken(array $sellerAccessToken): bool |
| 156 | { |
| 157 | return update_option($this->getSellerAccessTokenOptionName(), $sellerAccessToken); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Updates the partner link details |
| 162 | * |
| 163 | * @since 2.25.0 |
| 164 | */ |
| 165 | public function deleteSellerAccessToken(): bool |
| 166 | { |
| 167 | return delete_option($this->getSellerAccessTokenOptionName()); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Deletes the partner link details |
| 172 | * |
| 173 | * @since 2.11.1 |
| 174 | * @return bool |
| 175 | */ |
| 176 | public function canCollectBillingInformation() |
| 177 | { |
| 178 | return give_is_setting_enabled(give_get_option(self::COLLECT_BILLING_DETAILS_KEY)); |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * @since 2.16.2 |
| 183 | */ |
| 184 | public function isTransactionTypeDonation() |
| 185 | { |
| 186 | return 'donation' === $this->getTransactionType(); |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * This function returns the seller access token option name |
| 191 | * |
| 192 | * @since 2.25.0 |
| 193 | */ |
| 194 | private function getSellerAccessTokenOptionName(): string |
| 195 | { |
| 196 | return sprintf( |
| 197 | 'give_paypal_commerce_%s_seller_access_token', |
| 198 | give_is_test_mode() ? 'sandbox' : 'live' |
| 199 | ); |
| 200 | } |
| 201 | } |
| 202 |