First guest checkout store the commerce_remote_id for anonymous user and reuse in next guest checkout.

Payment details like email, description send to Stripe are empty.

Comments

quocnht created an issue. See original summary.

  • vasike committed fe7d2e1 on 8.x-1.x
    Issue #2869636 by quocnht, vasike: Fix for Guest checkout reuse...
vasike’s picture

Status: Active » Fixed

indeed.

Commited a fix for this : Do not save commerce_remote_id for anonymous.

Please re-open if it's not fixed.
Thank you

quocnht’s picture

Status: Fixed » Needs work

Applied patch and it does not save commerce_remote_id for anonymous anymore. But it throw an exception "Invalid parameters were supplied to Stripe's API" at createPayment:

    $transaction_data = [
      'currency' => $currency_code,
      'amount' => $this->formatNumber($amount->getNumber()),
      'customer' => $customer_id,
      'source' => $payment_method->getRemoteId(),
      'capture' => $capture,
    ];

    try {
      $result = \Stripe\Charge::create($transaction_data);
      ErrorHelper::handleErrors($result);
    }
    catch (\Stripe\Error\Base $e) {
      ErrorHelper::handleException($e);
    }
vasike’s picture

Status: Needs work » Postponed (maintainer needs more info)

i can't replicate this new issue.
@quocnht : could you, please, provide more details on this?
How exactly could be reproduced?

quocnht’s picture

Status: Postponed (maintainer needs more info) » Active

@vasike

Step to reproduced:

- Install new commerce project, with commerce_stripe, add a product for testing.

- Add to cart, check out as guest, provide a card, go to review it is ok, purchase it show error "We encountered an unexpected error processing your payment method. Please try again later."

- Check log message there are 2 error:

-- commerce_stripe "No such token: card_1AAGEKJbl4MR0znism5CB2JH"
-- commerce_payment "Invalid parameters were supplied to Stripe's API."

Check at Stripe backend, a customer still create with a card card_1AAGEKJbl4MR0znism5CB2JH.

I do some debug and find the $transaction_data have customer=>NULL.

I follow the stripe api at https://stripe.com/docs/api#create_charge . if you do not pass a customer ID, the source you provide must either be a token

*This also error when create a new account, and then login and checkout. It seem that the code at line 417 never reach, because of return on line 410.

    else {
      // Create both the customer and the payment method.
      try {
        $customer = \Stripe\Customer::create([
          'email' => $owner->getEmail(),
          'description' => $this->t('Customer for :mail', array(':mail' => $owner->getEmail())),
          'source' => $payment_details['stripe_token'],
        ]);
        $cards = \Stripe\Customer::retrieve($customer->id)->sources->all(['object' => 'card']);
        $cards_array = \Stripe\Util\Util::convertStripeObjectToArray([$cards]);
        $customer_id = $customer->id;
        foreach ($cards_array[0]['data'] as $card) {
          return $card;
        }
      }
      catch (\Stripe\Error\Base $e) {
        ErrorHelper::handleException($e);
      }
      if ($owner) {
        $owner->commerce_remote_id->setByProvider('commerce_stripe', $customer_id); *Line 417*
        $owner->save();
      }
    }

That's all I have for now. Thank you

  • vasike committed ec44569 on 8.x-1.x
    Issue #2869636 by quocnht, vasike: Anonymous Stripe payment broken.
    
vasike’s picture

Title: Guest checkout reuse commerce_remote_id » Anonymous Stripe payment broken
Status: Active » Needs review

indeed it seems Stripe payment is broken for Anonymous.

So the issue here is not to use customer in the Anonymous case.
So we need to use the card token for anonymous payment methods.

Here is a new commit that should fix or at least help with this issue.

Needs review and re-titled.

quocnht’s picture

Status: Needs review » Reviewed & tested by the community

It works. Thank you.

vasike’s picture

Status: Reviewed & tested by the community » Fixed

i think we can close this, as it seems there are some people helping with the (new) issues.

@quocnht : Actually, RTBC status is for patches before commit.
Anyway it was unusual also put the on "Needs review" after commit.
But, i needed support, and i got it ;)
thanks a lot!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.