duncanmcclean / simple-commerce

A simple, yet powerful e-commerce addon for Statamic.
https://statamic.com/addons/duncanmcclean/simple-commerce
Other
148 stars 42 forks source link

Stripe Issue #367

Closed MarcDerhammer closed 3 years ago

MarcDerhammer commented 3 years ago

When using the Stripe gateway (built in), if a cart does not already exist, getting an exception:

Return value of DoubleThreeDigital\SimpleCommerce\Orders\Cart\Drivers\SessionDriver::getCartKey() must be of the type string, null returned

This does not happen if I remove the {{ sc:checkout }} OR already have a cart in session. If I already have a cart, I am able to complete checkout using Stripe just fine.

Here is how I'm setting up the gateway:

\DoubleThreeDigital\SimpleCommerce\Gateways\StripeGateway::class => [ 'key' => env('STRIPE_KEY'), 'secret' => env('STRIPE_SECRET'), 'display' => 'Securely via Stripe' ],

How to reproduce

Use the Stripe gateway and start a fresh session.

What I expected

No exception.

Environment

Statamic 3.0.44 Pro Laravel 7.30.4 PHP 7.4.15 aryehraber/statamic-captcha 1.3.0 doublethreedigital/sc-digital-products 2.0.2 doublethreedigital/simple-commerce 2.2.9 statamic/seo-pro 2.1.1

Thank you! Please let me know if you need more info.

duncanmcclean commented 3 years ago

Hmm, it seems to be working fine for me if I have no cart. What does your cart array look like in your simple-commerce.php config file.

However, why would you be showing the checkout form to a customer if they've not got anything in their cart? 🤔

MarcDerhammer commented 3 years ago

'cart' => [ 'driver' => \DoubleThreeDigital\SimpleCommerce\Orders\Cart\Drivers\SessionDriver::class, 'key' => 'simple-commerce-cart', ],

Hm.. maybe I'm doing something else wrong.

Building a cart/checkout process using Vue and I just need the {{ client_secret }} available down there as I'd like the cart->checkout to be completed in the same component. I should probably do some refactoring to separate the two though if this is not the way to go.

duncanmcclean commented 3 years ago

'cart' => [ 'driver' => \DoubleThreeDigital\SimpleCommerce\Orders\Cart\Drivers\SessionDriver::class, 'key' => 'simple-commerce-cart', ],

Hm.. maybe I'm doing something else wrong.

Building a cart/checkout process using Vue and I just need the {{ client_secret }} available down there as I'd like the cart->checkout to be completed in the same component. I should probably do some refactoring to separate the two though if this is not the way to go.

Yeah, gateway's don't work if no cart exists. Stripe won't let us generate a client_secret if the amount is 0 anyway (as you can't pay for nothing haha).

The recommended way would be to load the gateway stuff once items have been added to the cart and you're wanting to display the checkout.

MarcDerhammer commented 3 years ago

Alrighty, that makes sense. thanks for your help!

duncanmcclean commented 3 years ago

Alrighty, that makes sense. thanks for your help!

Sure, no problem! Hope you have a good day 🙂