Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for business purchase is missing when using the checkout tag #335

Open
tomfischerNL opened this issue Jan 9, 2023 · 6 comments
Open
Assignees
Labels
question Further information is requested

Comments

@tomfischerNL
Copy link

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
Copy link
Author

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 ;)

@andrelopez
Copy link
Member

Hi @tomfischerNL Similar to #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 andrelopez self-assigned this Jan 12, 2023
@andrelopez andrelopez added the question Further information is requested label Jan 12, 2023
@tomfischerNL
Copy link
Author

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
Copy link
Author

Hi @andrelopez,

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

@tomfischerNL
Copy link
Author

Any status update on this?

@andrelopez
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants