0

I am using ignited/laravel-omnipay package for omnipay in laravel. I am trying to implement token billing using stripe as shown here https://github.com/thephpleague/omnipay#token-billing. Customer are getting created successfully on stripe but i am not able to make payment with the returned customer id.

Here's my code

    $token = Input::get('stripetoken');
    $gateway = Omnipay::create('Stripe');
    $gateway->setApiKey('My Key');
    $gateway->setTestMode(true);
    $cardresponse = $gateway->createCard(array('token' =>$token))->send();
    if ($cardresponse->isSuccessful()) {
      $card_id = $cardresponse->getCardReference();
      $data = $cardresponse->getData();
      $customerid = $data['id'];
      $cardid = $data['default_source'];
    }
    $paymentresponse = $gateway->purchase(array('amount' => '10.00','currency'  => 'USD', 'cardReference' => $card_id))->send();
    echo $paymentresponse->getMessage();

I am getting following response.

No such token: cus_8FwPaLNKdWcfRW

And when i check my stripe dashboard then customer with this id exists and has a card assigned. Thanks for helping.

ALOK
  • 553
  • 6
  • 17

1 Answers1

2

Since you're creating a customer object, you need to update your charge creation request to pass the customer ID in the customer parameter rather than in the source parameter (which causes the error you're seeing).

I'm not familiar with Omnipay but I think this should work:

$paymentresponse = $gateway->purchase(array('amount' => '10.00','currency'  => 'USD', 'customerReference' => $card_id))->send();
Ywain
  • 16,854
  • 4
  • 51
  • 67