My code creates and loads the Stripe Checkout where the customer enters name and card details and is returned to a php script where the token is received and used to create a Stripe customer and then send a purchase request to charge their card.
How would I best add a subscription using the same card and the omnipay library where possible? Do I use the token or grab the source id from the purchase object and use that, and create a subscription after the purchase?
Inside a class, the call to createSubscription in the code below gives the error "This customer has no attached payment source".
public function createSubscription($token,$customer_id,$plan,$source_id)
{
try {
$response = $this->gateway->createSubscription(
array(
'customerReference' => $customer_id,
'plan' => $plan,
'source' => $token
)
)->send();
if ($response->isSuccessful()) {
$data = $response->getData();
return $data;
}
} catch (Exception $e) {
$message = "Error creating Stripe subscription: " . $e->getMessage();
return;
}
}