LokiCheckout_PaypalCompletePayments
This Magento 2 module is an add-on package to the LokiCheckout.
Installation
This module integrates PayPal Complete Payments
(paypal/module-ppcp, Magento module PayPal_PPCP) into the Loki Checkout. Install both via composer:
composer require loki-checkout/magento2-paypal-complete-payments bin/magento module:enable PayPal_PPCP LokiCheckout_PaypalCompletePayments bin/magento setup:upgrade
PayPal_PPCP declares a module sequence on Magento_Inventory and Magento_InventorySales, so a shop without
MSI needs these modules (and the Inventory API modules they depend on) enabled.
Configuration
Configure PayPal Complete Payments in the Admin Panel under Stores > Configuration > Sales > Payment Methods > PayPal Complete Payments. This module uses the upstream configuration as it is:
| Configuration | Path | Notes |
|---------------|------|-------|
| Enable the extension | payment/paypal_complete_payments/is_active | |
| Environment | payment/paypal_complete_payments/ppcp_environment | sandbox or production |
| REST client ID and secret | payment/paypal_complete_payments/client_id_<env>, client_secret_<env> (website scope) | the secret is stored encrypted |
| Merchant onboarding | table ppcp_merchant | created by the PPCP onboarding in the Admin Panel. Without an onboarded merchant (a row with a merchant_id for the website and environment) the Loki Checkout does not offer any PPCP method |
| Per method | payment/ppcp_<method>/active, payment_action (authorize or authorize_capture) | |
| 3D Secure | payment/ppcp_card/three_d_secure, payment/ppcp_googlepay/three_d_secure | the Loki Checkout also checks the 3D Secure result on the server |
| APMs | payment/ppcp_apm/allowed_methods | |
| Pay Later | payment/ppcp_paypal/enable_paylater, message_enable | |
| Express buttons | payment/ppcp_<paypal,venmo,applepay,googlepay>/show_on_shipping | shown in the fast checkout area of the Loki Checkout |
| Fastlane | payment/ppcp_fastlane/is_active | guests only |
| Sandbox buyer country | payment/ppcp_paypal/buyer_country | only sent to the PayPal SDK in the sandbox |
Supported payment methods
| Method | Code | How it works in the Loki Checkout |
|--------|------|-----------------------------------|
| PayPal (+ Pay Later) | ppcp_paypal | PayPal buttons; the order is placed right after the approval in the PayPal window |
| Venmo | ppcp_venmo | Venmo button (US buyers only) |
| Card | ppcp_card | PayPal card fields; the Place Order button submits the card (3D Secure included) |
| Fastlane | ppcp_card | for guests, the card fields are replaced by the Fastlane card component when Fastlane is enabled |
| Stored cards | ppcp_card_vault | logged-in customers with a stored card; the Place Order button charges the stored card |
| Stored PayPal/Venmo accounts | ppcp_paypal_vault, ppcp_venmo_vault | PayPal/Venmo buttons with the stored account |
| Apple Pay | ppcp_applepay | Apple Pay button (Safari with Apple Pay and HTTPS only) |
| Google Pay | ppcp_googlepay | Google Pay button, including the 3D Secure payer action |
| Alternative payment methods | ppcp_apm | a list of the allowed and eligible APMs (Bancontact, BLIK, eps, iDEAL, Multibanco, MyBank, Przelewy24, Trustly) with their PayPal buttons; Pay with Crypto redirects to PayPal; Pay Upon Invoice asks for the date of birth |
| Express | ppcp_paypal, ppcp_venmo, ppcp_applepay, ppcp_googlepay | buttons in the fast checkout area |
Rules of paypal/module-ppcp that also apply here:
- Pay Upon Invoice is only offered in the
de_DElocale, for German addresses and order totals between 5 and 2500. - Pay with Crypto is only offered in the
en_USlocale or with the base currency USD. - All amounts are sent to PayPal in the base currency of the store.
- The PayPal and Venmo express buttons let PayPal collect the shipping address and call the shop back on
/ppcp/shipping/callback. These callbacks only work when PayPal can reach the shop (not on a local development host). Withpayment/ppcp_paypal/skip_review_pagedisabled, the buyer goes to the PPCP review page instead.
How the payment flow works
- The Loki component of the payment method loads the PayPal JS SDK (with the PPCP partner attribution ID).
- The PayPal order is created by the upstream REST endpoint
POST /rest/V1/ppcp/createGuestOrder(the masked quote ID is used for guests and customers). This reserves the Magento order ID and binds the PayPal order to the quote (invoice_id= reserved order ID + merchant tracking ID). - After the approval (PayPal window, card fields, wallet sheet), the component saves the PayPal order ID on the quote payment and places the order with the Loki Checkout.
- Before the order is placed, the FinalStep task
PaypalCompletePaymentsTaskchecks that the PayPal order ID belongs to this quote, that the PayPal order total still equals the quote total and (for cards and Google Pay) that the 3D Secure liability shifted. If not, the customer returns to the checkout with an error. - The upstream gateway commands authorize or capture the PayPal order.
The express Google Pay and Apple Pay buttons use the controllers lokippcp/express/estimate, prepare and
placeorder to collect shipping rates, store the wallet addresses and place the order through the Loki Checkout.
Troubleshooting
- Every PayPal API call is logged to
var/log/ppcp.logbypaypal/module-ppcp. Note that this log contains the REST client secret and access tokens: protect it and clean it up. - When the PayPal API returns an error with line breaks in its body (like a
503),paypal/module-ppcpfails with "Reason phrase must not contain CR or LF characters"; the customer sees "Cannot create PayPal order".
Tests
- Unit tests:
Test/Unit. - Integration tests:
Test/Integration. They fake the PayPal API withTest/Integration/Stub/FakeRequestHandler. - Playwright tests:
Test/Playwright. The fixture moduleLokiCheckout_PaypalCompletePaymentsTestFixture(Test/Fixture/PaypalCompletePaymentsTestFixture, never install it in production) fakes the onboarded merchant (loki_checkout_test/ppcp/merchant_id) and optionally the PayPal API (loki_checkout_test/ppcp/fake_api). The specscheckout-render-testandfake-order-testreplace the PayPal JS SDK with a stub;sandbox-testuses the real PayPal sandbox whenPAYPAL_REST_CLIENT_ID,PAYPAL_REST_CLIENT_SECRET(and for the PayPal windowPAYPAL_BUYER_EMAIL,PAYPAL_BUYER_PASSWORD) are set.
Current status
@dev
to the composer command.
Support
For getting support, create an Issue under the following project URL:
https://gitlab.loki-extensions.com/loki-checkout/LokiCheckout_PaypalCompletePayments.git
Module Dependencies
The following dependencies are declared in the module its `etc/module.xml` file:
LokiCheckout_Core
Loki_Base
Loki_Components
Loki_CssUtils
Loki_FieldComponents
Loki_MapComponents
Magento_Backend
Magento_Catalog
Magento_Checkout
Magento_CheckoutAgreements
Magento_Config
Magento_Csp
Magento_Customer
Magento_Directory
Magento_Eav
Magento_Inventory
Magento_InventoryAdminUi
Magento_InventoryAdvancedCheckout
Magento_InventoryApi
Magento_InventoryBundleImportExport
Magento_InventoryBundleProduct
Magento_InventoryBundleProductAdminUi
Magento_InventoryBundleProductIndexer
Magento_InventoryCache
Magento_InventoryCatalog
Magento_InventoryCatalogAdminUi
Magento_InventoryCatalogApi
Magento_InventoryCatalogFrontendUi
Magento_InventoryCatalogRule
Magento_InventoryCatalogSearch
Magento_InventoryCatalogSearchBundleProduct
Magento_InventoryCatalogSearchConfigurableProduct
Magento_InventoryConfigurableProduct
Magento_InventoryConfigurableProductAdminUi
Magento_InventoryConfigurableProductFrontendUi
Magento_InventoryConfigurableProductIndexer
Magento_InventoryConfiguration
Magento_InventoryConfigurationApi
Magento_InventoryDistanceBasedSourceSelection
Magento_InventoryDistanceBasedSourceSelectionAdminUi
Magento_InventoryDistanceBasedSourceSelectionApi
Magento_InventoryElasticsearch
Magento_InventoryExportStock
Magento_InventoryExportStockApi
Magento_InventoryGroupedProduct
Magento_InventoryGroupedProductAdminUi
Magento_InventoryGroupedProductIndexer
Magento_InventoryImportExport
Magento_InventoryInStorePickup
Magento_InventoryInStorePickupAdminUi
Magento_InventoryInStorePickupApi
Magento_InventoryInStorePickupFrontend
Magento_InventoryInStorePickupMultishipping
Magento_InventoryInStorePickupQuote
Magento_InventoryInStorePickupSales
Magento_InventoryInStorePickupSalesAdminUi
Magento_InventoryInStorePickupSalesApi
Magento_InventoryInStorePickupShipping
Magento_InventoryInStorePickupShippingAdminUi
Magento_InventoryInStorePickupShippingApi
Magento_InventoryInStorePickupWebapiExtension
Magento_InventoryIndexer
Magento_InventoryLowQuantityNotification
Magento_InventoryLowQuantityNotificationAdminUi
Magento_InventoryLowQuantityNotificationApi
Magento_InventoryMultiDimensionalIndexerApi
Magento_InventoryProductAlert
Magento_InventoryRequisitionList
Magento_InventoryReservationCli
Magento_InventoryReservations
Magento_InventoryReservationsApi
Magento_InventorySales
Magento_InventorySalesAdminUi
Magento_InventorySalesApi
Magento_InventorySalesAsyncOrder
Magento_InventorySalesFrontendUi
Magento_InventorySetupFixtureGenerator
Magento_InventoryShipping
Magento_InventoryShippingAdminUi
Magento_InventorySourceDeductionApi
Magento_InventorySourceSelection
Magento_InventorySourceSelectionApi
Magento_InventoryStockVisualizer
Magento_InventorySwatchesFrontendUi
Magento_InventoryVisualMerchandiser
Magento_InventoryWishlist
Magento_Newsletter
Magento_Payment
Magento_Paypal
Magento_Quote
Magento_Sales
Magento_Shipping
Magento_Store
Magento_Tax
Magento_Ui
Magento_Vault
PayPal_PPCP
Yireo_CspUtilities
Composer details
LokiCheckout_PaypalCompletePaymentsloki-checkout/magento2-paypal-complete-payments
ext-json: *
ext-pcre: *
loki-checkout/magento2-core: ^2.8
loki/magento2-components: ^2.8
loki/magento2-css-utils: ^1.0
magento/framework: ^103.0
magento/module-checkout: ^100.4
magento/module-directory: ^100.4
magento/module-payment: ^100.4
magento/module-quote: ^101.2
magento/module-store: ^101.1
magento/module-vault: ^101.2
paypal/module-ppcp: ^6.1
php: >=8.2 <8.6