#MikeD-error
1 messages · Page 1 of 1 (latest)
hi there! can you share the request id [0]? it'd look like req_xxx
[0] https://support.stripe.com/questions/finding-the-id-for-an-api-request
req_acoSRFzYrxZDlK
public function createSource (Customer $customer, Token $token): Source
{
try{
$stripeSource = $this->sc->sources->create([
'customer' => $customer->id,
// 'type' => 'card',
'token' => $token->id,
]);
} catch (ApiErrorException $e) {
throw (new Exception($e->getMessage() . ' | ' . $e->getCode() . ' Line # ' . $e->getLine()));
// throw (new Exception($e));
}
return $stripeSource;
}
Received unknown parameter: token
I am getting a token from stripe vuejs card element. Passing that to backend
backend runs
$stripeToken = $stripeService->checkToken($request->stripeToken['id']);
Stripe Service
public function checkToken (string $token_id): Token
{
try{
return $this->sc->tokens->retrieve(
$token_id, []
);
} catch (ApiErrorException $e) {
throw (new Exception($e->getMessage()));
}
}
Trying to associate the card that the vuejs element gave back to me (the token anyways) . Maybe there is a better way?
Method that is erroring
/**
* Create a Source for a Customer
*
* @param Customer $customer
* @param Token $token
* @return Source
* @throws Exception
*/
public function createSource (Customer $customer, Token $token): Source
{
try{
$stripeSource = $this->sc->sources->create([
'customer' => $customer->id,
// 'type' => 'card',
'token' => $token->id,
]);
} catch (ApiErrorException $e) {
throw (new Exception($e->getMessage() . ' | ' . $e->getCode() . ' Line # ' . $e->getLine()));
// throw (new Exception($e));
}
return $stripeSource;
}
👀
I mean according to the API I should be able to pass token
for creating the source.
Do I need to pass the whole token?
looking into this, gimme a while
No worries. Thanks
Can I ask you this.. Am I doin the right thing? In the sense of. VueJS element returns a token. For the card. Is this how I am to associate the card to the newly created customer?
as I see in the token I get back
[2022-05-12 04:28:56] dev.EMERGENCY: Stripe\Token JSON: {
"id": "tok_1KyTZpGbltLCtZUAa8eAjetj",
"object": "token",
"card": {
"id": "card_1KyTZpGbltLCtZUASSzphubG",
I have the card ref as well
so i'm not familiar with vueJS, but you should be using PaymentIntents and PaymentMethods
tokens and charges are deprecated already
you can take a look at this guide : https://stripe.com/docs/payments/accept-a-payment but unfortunately we don't have a vueJS example in our documentation
Yes. But how do you create a payment method for a customer with tokens? That's all your VUEJS gives to me
Because that's all I am allowed to see on my end
For example. Customer has 5 credit cards on File. He wants to rotate the cards from month to month manually.
Customer->getCards
Cards [last4 => 1234], [last4 => 4321]
Customer Picks second card. -> re associate this payment method with the subscription that's associated to the customer etc..
sorry about the delay, to attach the card token to the customer, you would want to use this API request instead : https://stripe.com/docs/api/cards/create
Yes but this requires PCI compliance
The correct answer is . to create a payment method and use backwards compatibility
/**
* @param Customer $customer
* @param PaymentMethod $paymentMethod
* @return void
* @throws Exception
*/
public function attachPaymentMethodToCustomer (Customer $customer, PaymentMethod $paymentMethod): void
{
try{
$this->sc->paymentMethods->attach(
$paymentMethod->id, ['customer' => $customer->id]
);
} catch (ApiErrorException $e) {
throw (new Exception($e->getMessage() . ' | ' . $e->getCode() . ' Line # ' . $e->getLine()));
}
}
/**
* Create a Source for a Customer
*
* @param Customer $customer
* @param Token $token
* @return PaymentMethod
* @throws Exception
*/
public function createPaymentMethod (Customer $customer, Token $token): PaymentMethod
{
try{
$stripePaymentMethod = $this->sc->paymentMethods->create([
'type' => 'card',
'card' => [
'token' => $token->id,
]
]);
} catch (ApiErrorException $e) {
throw (new Exception($e->getMessage() . ' | ' . $e->getCode() . ' Line # ' . $e->getLine()));
// throw (new Exception($e));
}
return $stripePaymentMethod;
}
iwhen using that particular API request, you're passing in the token in the source parameter
Yes, because that is how I thought it was supposed to be done
const stripe = require('stripe')('sk_test_...');
const card = await stripe.customers.createSource(
'cus_4QE4bx4C5BVSrC',
{source: 'tok_amex'}
);
there's no handling of raw card numbers here so you're still PCI compliant
Yes I see how you're doing that there
I used the payment method Since that seems to be the new way and it is backwards compatible.
$stripePaymentMethod = $this->sc->paymentMethods->create([
'type' => 'card',
'card' => [
'token' => $token->id,
]
]);
Shall I create a separate thread for the issue I am having with the subscription now?
req_KgLrropQi5W9hj
ah yeah, you can create a PaymentMethod that way too
we can continue discussion on the same thread
you should provide the Price in https://stripe.com/docs/api/subscriptions/create#create_subscription-items-price
if you look at the post request in the log, you're passing it as items[0]
from what I understood you could have multiple price items
items is an array of objects
So, Should I just pass an array with the plan then. Dont' worry about extracting the ID etc.
PHP
$stripe = new \Stripe\StripeClient(
'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
);
$stripe->subscriptions->create([
'customer' => 'cus_4QE4bx4C5BVSrC',
'items' => [
['price' => 'price_1KyU2R2eZvKYlo2CF7UEm9Dh'],
],
]);```
your code doesn't define the price key
yes understood
What if you have more than one price?
[price => ['price1','price2']]
?
'items' => [
['price' => 'price_1'],
['price' => 'price_2'],
],
ahhh I missread your first one
I didn't see the other array wrapping the price assos array
Well. Looks like I am getting there.
On to more errors. Thanks @pseudo talon
I think I am calling it a night tonight lol
great! feel free to reach out again if you run into any other issues!