#whip-php
1 messages · Page 1 of 1 (latest)
you should never reinstantiate it in every method. The stripe instance should be a singleton.
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;
}
}
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.
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.
Sorry for the long wait. Yes you can also use singleton pattern in your PHP code to have one global instance of StripeClient.