stripe icon indicating copy to clipboard operation
stripe copied to clipboard

Option for business purchase is missing when using the checkout tag

Open tomfischerNL opened this issue 3 years ago • 6 comments

Description

When creating a checkout link in Stripe, I have the option to check if a user can select if the purchase is a business purchase. Then you get 2 more fields in stripe when you pay. Business name and VAT number.

But when creating a checkout link from Enupal, this option is not available. Can you add this option as well?

tomfischerNL avatar Jan 09 '23 12:01 tomfischerNL

I fixed this issue for myself, in the services/Checkout.php I changed the following code:

if ($form->automaticTax) {
    $sessionParams['automatic_tax'] = [
        'enabled' => true
    ];

    if (isset($sessionParams['customer'])) {
        $sessionParams['customer_update'] = [
            'shipping' => 'auto'
        ];
    }
}

I used the $sessionParams['customer'] outside the automatic Tax block, and added the tax_id_collection parameter.

Like this:

if ($form->automaticTax) {
    $sessionParams['automatic_tax'] = [
        'enabled' => true
    ];
}

if (isset($sessionParams['customer'])) {
    $sessionParams['customer_update'] = [
        'name' => 'auto',
        'shipping' => 'auto'
    ];
}

$sessionParams['tax_id_collection']['enabled'] = true;

Maybe this helps you to implement it ;)

tomfischerNL avatar Jan 12 '23 17:01 tomfischerNL

Hi @tomfischerNL Similar to https://github.com/enupal/stripe/issues/334 this is also a great use case to use the beforeCreateSession event:

use enupal\stripe\services\Checkout;
use enupal\stripe\events\CheckoutEvent;
use enupal\stripe\Stripe;
use craft\base\Plugin;
use Craft;

class YourPlugin extends Plugin
{
    public function init()
    {
        ....
        ....
     
         Event::on(Checkout::class, Checkout::EVENT_BEFORE_CREATE_SESSION, function(CheckoutEvent $e) {
              $isCart = $e->isCart;
              $sessionParams = $e->sessionParams;
              //overwrite $sessionParams
              $sessionParams['tax_id_collection']['enabled'] = true;
              if (isset($sessionParams['customer'])) {
                    $sessionParams['customer_update'] = [
                          'name' => 'auto',
                          'shipping' => 'auto'
                   ];
               }
              $e->sessionParams = $sessionParams;
         });
        ...
        ...        
     }
}  

Please let me know if you have any questions

andrelopez avatar Jan 12 '23 18:01 andrelopez

Thanks!

Maybe you can think of a way to implement the $sessionParams['tax_id_collection']['enabled'] = true; tag, as an option to the forms or in the back-end, for example in the sidebar, where you can also check if you want to show the shipping address etc. Because it is a regular option if you create a payment in stripe itself :)

Schermafbeelding 2023-01-12 om 19 37 19

tomfischerNL avatar Jan 12 '23 18:01 tomfischerNL

Hi @andrelopez,

Do you have some more info about this? How can I add the "Business purchase" / VAT number to the checkout tag?

tomfischerNL avatar Nov 22 '23 12:11 tomfischerNL

Any status update on this?

tomfischerNL avatar Dec 05 '23 15:12 tomfischerNL

Hi @tomfischerNL could you please confirm your Craft CMS version?

andrelopez avatar Dec 08 '23 20:12 andrelopez