#whip-php

1 messages · Page 1 of 1 (latest)

minor smelt
#

you should never reinstantiate it in every method. The stripe instance should be a singleton.

stiff quest
#

Am I doing this correctly now?
Subscriptions

class Subscription {
    public __constructor(){
        $stripe = Stripe::getInstance(); // call this in every method?
    }
}

Stripe.php

class Stripe {
    
    private static $inst;

    private function __construct(){
        return new \Stripe\StripeClient('SECRETKEY');
    }

    public function getInstance(){
        if(!isset(self::$inst))
            self::$obj = new Stripe();

        return self::$obj;
    }
}
clever veldt
#

Hi @stiff quest you can take a look at Stripe example repo and see how it shares the Stripe instance https://github.com/stripe-samples/accept-a-payment/tree/main/custom-payment-flow/server/php/public

e.g., it creates a stripe instance in the shared.php file, and reuse it in other php file.

GitHub

Learn how to accept a payment from customers around the world with a variety of payment methods. - accept-a-payment/custom-payment-flow/server/php/public at main · stripe-samples/accept-a-payment

stiff quest
#

I don't see where the classes are? This is how I use it elsewhere but I'm building the subscription system on OOP and I can't access it simply, besides using global $stripe.

clever veldt
#

Sorry for the long wait. Yes you can also use singleton pattern in your PHP code to have one global instance of StripeClient.