Wesley Schravendijk
Wesley Schravendijk

Reputation: 497

Create charge using Stripe in Laravel working in test mode but not in live

Hope somebody can help me with this one. I am clueless right now.

I just started stripe for the first time. Looks like an amazing service.

Have created a test application and started testing. Everything works as it should.

Now after signing up, I want to go live. Here is where the problem occurs.

Somehow, it keeps saying no such token, when I can see the token standing in the stripe account. The id of the account and our database is completely the same.

Stripe::setApiKey('[our live token]'); 

/*
* create new customer
*/
$results = \Stripe\Charge::create([
   "amount"            =>          '10',
   "currency"          =>          "jpy",
   "source"            =>          $getCommission->unique_id,
   "description"       =>          "test charge"
]);

Anybody has ever experienced this?

It keeps saying the following

No such token: cus_EuguGZgeDoCxBj

Help is highly appriciated.

Wesley

Upvotes: 0

Views: 993

Answers (1)

Surender Singh Rawat
Surender Singh Rawat

Reputation: 919

You are providing customer id instead of source token.

Source Token :

Source token is token which is used for referenced of your cards. Generated from Stripe.js

\Stripe\Stripe::setApiKey("sk_test_4eC39HqLyjWDarjtT1zdp7dc");

\Stripe\Charge::create([
      "amount" => 2000,
      "currency" => "usd",
      "source" => "tok_amex", // obtained with Stripe.js
      "description" => "Charge for [email protected]"
 ]);

How to get Default Source :

  1. Get Stripe Customer
  2. Get default source on the Behalf of that customer

      \Stripe\Stripe::setApiKey("sk_test_4eC39HqLyjWDarjtT1zdp7dc");
    
      $customer = \Stripe\Customer::retrieve('cus_EkSwM3JX7f0ueA');
      $customer->default_source; // use this as source token
    

    Use default source as source token

Upvotes: 1

Related Questions