#MikeD-error

1 messages · Page 1 of 1 (latest)

pseudo talon
quiet egret
#

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;
    }
pseudo talon
#

👀

quiet egret
#

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?

pseudo talon
#

looking into this, gimme a while

quiet egret
#

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

pseudo talon
#

so i'm not familiar with vueJS, but you should be using PaymentIntents and PaymentMethods

#

tokens and charges are deprecated already

quiet egret
#

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..

pseudo talon
quiet egret
#

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;
    }
pseudo talon
#

iwhen using that particular API request, you're passing in the token in the source parameter

quiet egret
#

Yes, because that is how I thought it was supposed to be done

pseudo talon
#
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

quiet egret
#

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

pseudo talon
#

ah yeah, you can create a PaymentMethod that way too

#

we can continue discussion on the same thread

quiet egret
pseudo talon
quiet egret
pseudo talon
#

if you look at the post request in the log, you're passing it as items[0]

quiet egret
#

from what I understood you could have multiple price items

pseudo talon
#

items is an array of objects

quiet egret
#

So, Should I just pass an array with the plan then. Dont' worry about extracting the ID etc.

pseudo talon
#


PHP

$stripe = new \Stripe\StripeClient(
  'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
);
$stripe->subscriptions->create([
  'customer' => 'cus_4QE4bx4C5BVSrC',
  'items' => [
    ['price' => 'price_1KyU2R2eZvKYlo2CF7UEm9Dh'],
  ],
]);```
quiet egret
#

Translates to the same thing

#

ahh ok

pseudo talon
#

your code doesn't define the price key

quiet egret
#

yes understood

#

What if you have more than one price?

#

[price => ['price1','price2']]
?

pseudo talon
#
'items' => [
    ['price' => 'price_1'],
    ['price' => 'price_2'],
  ],
quiet egret
#

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

pseudo talon
#

great! feel free to reach out again if you run into any other issues!