$mode ) ); } try { Stripe::setApiKey( $secret ); \Stripe\Balance::retrieve(); update_option( 'aimslms_stripe_connection_status_' . $mode, 'connected' ); return array( 'mode' => $mode, ); } catch ( ApiErrorException $e ) { update_option( 'aimslms_stripe_connection_status_' . $mode, 'not_connected' ); return new WP_Error( 'stripe_connection_failed', $e->getMessage(), array( 'mode' => $mode ) ); } } /** * LEGACY CHARGE (OPTIONAL) * Creates a legacy Stripe Charge from a card token. * * @param float $amount Charge amount in the major currency unit (converted to cents). * @param string $token Stripe card token to charge. * @param string $description Charge description. * @return \Stripe\Charge Created Stripe charge object. */ public static function charge( $amount, $token, $description ) { self::init(); return Charge::create( array( 'amount' => (int) round( $amount * 100 ), 'currency' => aimslms_get_stripe_currency_code(), 'description' => $description, 'source' => $token, ) ); } /** * PAYMENT INTENT (RECOMMENDED) * Creates a Stripe PaymentIntent for the given amount. * * @param float $amount Payment amount in the major currency unit (converted to cents). * @param string $currency Currency code. * @param string $description Payment description. * @param string $order_id Local order ID stored in the intent metadata. * @return \Stripe\PaymentIntent Created Stripe payment intent object. */ public static function create_payment_intent( $amount, $currency, $description, $order_id ) { self::init(); return PaymentIntent::create( array( 'amount' => (int) round( $amount * 100 ), 'currency' => strtolower( $currency ), 'description' => $description, 'metadata' => array( 'order_id' => $order_id, ), ) ); } /** * Retrieves a Stripe PaymentIntent by ID. * * @param string $intent_id Stripe PaymentIntent ID. * @return \Stripe\PaymentIntent Retrieved payment intent object. */ public static function retrieve_payment_intent( $intent_id ) { self::init(); return PaymentIntent::retrieve( $intent_id ); } /** * Retrieves a Stripe Charge by ID. * * @param string $charge_id Stripe Charge ID. * @return \Stripe\Charge Retrieved charge object. */ public static function retrieve_payment_charge( $charge_id ) { self::init(); return Charge::retrieve( $charge_id ); } }