WebhookHandlers
4 months ago
APIClass.php
3 years ago
Helpers.php
1 month ago
PaymentHelpers.php
3 months ago
Stripe.php
3 months ago
WebhookHelpers.php
8 months ago
index.php
3 years ago
APIClass.php
73 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Membership\PaymentMethods\Stripe; |
| 4 | |
| 5 | use ProfilePressVendor\Stripe\Stripe as Stripe; |
| 6 | use ProfilePressVendor\Stripe\StripeClient; |
| 7 | use WP_Error; |
| 8 | |
| 9 | class APIClass |
| 10 | { |
| 11 | /** |
| 12 | * Configures the Stripe API before each request. |
| 13 | */ |
| 14 | public static function _setup() |
| 15 | { |
| 16 | /** |
| 17 | * Sets application info for all proceeding requests. |
| 18 | * @link https://stripe.com/docs/building-plugins#setappinfo |
| 19 | */ |
| 20 | Stripe::setAppInfo( |
| 21 | 'ProfilePress', |
| 22 | PPRESS_VERSION_NUMBER, |
| 23 | 'https://profilepress.com', |
| 24 | 'pp_partner_LLG1ywQG7y6Ogw' |
| 25 | ); |
| 26 | |
| 27 | /** |
| 28 | * Sets API version for all proceeding requests. |
| 29 | * @link https://stripe.com/docs/building-plugins#set-api-version |
| 30 | */ |
| 31 | Stripe::setApiVersion(PPRESS_STRIPE_API_VERSION); |
| 32 | |
| 33 | $secret_key = Helpers::get_secret_key(); |
| 34 | |
| 35 | Stripe::setApiKey(trim($secret_key)); |
| 36 | |
| 37 | Stripe::setMaxNetworkRetries(2); |
| 38 | |
| 39 | Stripe::setEnableTelemetry(false); |
| 40 | |
| 41 | return new StripeClient(trim($secret_key)); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @return StripeClient |
| 46 | */ |
| 47 | public static function stripeClient() |
| 48 | { |
| 49 | return self::_setup(); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @param $account_id |
| 54 | * |
| 55 | * @return array|WP_Error |
| 56 | * |
| 57 | * @throws \Exception |
| 58 | */ |
| 59 | public function get_account($account_id) |
| 60 | { |
| 61 | try { |
| 62 | |
| 63 | return self::stripeClient()->accounts->retrieve($account_id)->toArray(); |
| 64 | |
| 65 | } catch (\Exception $e) { |
| 66 | |
| 67 | ppress_log_error(__METHOD__ . '(): ' . $e->getMessage()); |
| 68 | |
| 69 | throw new \Exception($e->getMessage(), $e->getCode()); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 |