craftcms / commerce-paypal-checkout

PayPal Checkout gateway for Craft Commerce.
https://plugins.craftcms.com/commerce-paypal-checkout
MIT License
5 stars 10 forks source link

Problem with multi-site setup #67

Closed vandres closed 1 year ago

vandres commented 1 year ago

Description I found an issue with my multi-site setup. I am having 6 sites:

image

Products are only available in the shop sites, not in the CMS part.

When I am in the checkout and want to proceed with PayPal, the form looks correct:

image

Different to e.g. the manual Gateway though, the payment-form of this Plugin is sending its request directly to the action url. In my case 'http://zs.test/index.php?p=actions/commerce/payments/pay'

image

I debugged a little into the Request class of Craft. Since the request url is now "zs.test" and not "zs.test/shop", Craft takes the CMS-site as the current site. Then Commerce recalculates the cart. Since there are no active products in the CMS, the cart will be empty.

Maybe I am doing something wrong. If not, Craft offers to send a siteToken or a site header with the requests. Maybe that could resolve that issue.

Additional info

  "require": {
    "craftcms/cms": "^4.2.0.2",
    "craftcms/commerce": "^4.1.0",
    "craftcms/commerce-paypal-checkout": "^2.1.0.2",
    "craftcms/redactor": "^3.0",
    "mmikkel/cp-field-inspect": "^1.4",
    "nystudio107/craft-vite": "^4.0",
    "php-http/curl-client": "^2.2",
    "putyourlightson/craft-elements-panel": "^2.0",
    "putyourlightson/craft-sprig": "^2.1",
    "sebastianlenz/linkfield": "^2.1",
    "spatie/craft-ray": "^2.0",
    "spicyweb/craft-neo": "^3.2",
    "typesense/typesense-php": "^4.8",
    "vaersaagod/geomate": "^2.0",
    "verbb/expanded-singles": "^2.0",
    "verbb/field-manager": "^3.0",
    "verbb/tablemaker": "^4.0",
    "verbb/wishlist": "^2.0",
    "vlucas/phpdotenv": "^5.4.0"
  },
  "require-dev": {
    "deployer/deployer": "^7.0",
    "roave/security-advisories": "dev-master",
    "yiisoft/yii2-shell": "^2.0.3"
  },
vandres commented 1 year ago

Got it working, by changing the template to the following:

<div class="paypal-rest-form" data-env="{{ gateway.testMode ? 'sandbox' : 'production' }}"
     data-prepare="{{ actionUrl('commerce/payments/pay', {'siteToken': currentSite.id|hash }) }}"
     data-complete="{{ actionUrl('commerce/payments/complete-payment', {'siteToken': currentSite.id|hash }) }}">
  <div id="paypal-button-container"></div>
</div>
nfourtythree commented 1 year ago

Hi @vandres

Thank you for your message.

Just to clarify you need this because you specifically want to post the data to a different URL/site?

Because, in testing this all works as expected if you are browsing the site you are wanting to submit the payment on.

Thanks

vandres commented 1 year ago

Thanks for the reply @nfourtythree

I don't really need a different url, but I need the siteToken included in my setup.

So you have a test setup, with the commerce url underneath the "normal" url and it works for you? The products are also disabled in the normal url?

Normal: example.com Shop: example.com/shop

nfourtythree commented 1 year ago

Hi @vandres

Thank you, due to the information you provided I went back and did some more testing and managed to replicate the issue.

From that, we have just pushed up a fix fo this which will be included in the next release of the plugin (likely to be soon).

Thanks!

vandres commented 1 year ago

@nfourtythree Is this fix released, yet?