Debugging on the local environment - developer manual

Debugging on the local environment - developer manual

Due to the fact that communication with InPost Pay is bilateral, i.e. Magento and InPost Pay API send requests to each other, debugging on the local environment is not that straightforward. For that reason, it is necessary to simulate requests sent from InPost Pay servers to the local environment, e.g. via the Postman or Insomnia software, etc.

 

Preparation of the local environment for debugging communication with InPost Pay

  1. Requests received from InPost Pay have a signature that is authorized bilaterally. It is not possible to send a test request without signature authorization. However, if it is a local or test environment that is adequately secured against external clients, the file specified below can be modified for that purpose by adding a method that always returns a correct request signature verification value in the first line.

\InPost\InPostPay\Plugin\Authorization\SignatureValidationPolicyPlugin::isSignatureValid

After modification, the code (between lines 64 and 65, "return true;" fragment) should look as follows:

protected function isSignatureValid(): bool { return true; //ommit signature validation $endpoint = $this->restRequest->getRequestUri(); $requestSignature = (string)$this->restRequest->getHeader(self::X_SIGNATURE_HEADER, ''); $requestSignatureTimestamp = (string)$this->restRequest->getHeader(self::X_SIGNATURE_TIMESTAMP_HEADER, ''); $requestPublicKeyVersion = (string)$this->restRequest->getHeader( self::X_SIGNATURE_PUBLIC_KEY_VERSION_HEADER, '' ); ...

Note! It is critical not to save that change in the file versioning system by mistake and for that change not to be implemented on the production environment, as in such case requests will not be subject to verification!

  1. Enable full logs in the InPost Pay configuration: Store->Config->Sales->Payment->InPost Pay->Debugging Settings->Log Level: DEBUG

  2. You will also need access to the database, more precisely to data in the array:

    inpost_pay_quote

    in column:

    basket_id

    These values will be necessary for communication with Magento through the Postman app as the basket ID. More information on Postman->Magento communication can be found below.

Example of a Magento<->InPost Pay communication scenario

  1. In the browser, at the local address of the store, go to the product catalog, then to the product page (depending on the InPost Pay Widget display configuration – if it is enabled on the product card, add the product with InPost Pay, if the Widget is displayed only in the shopping basket add the product to the shopping basket, and then from the shopping basket or minicart subpage start pairing the basket with InPost Pay)

  1. Once the form is opened, enter a phone number, it does not have to be a real phone number:

    image-20240912-095055.png

  2. Then check inpost_pay_quote.basket_id in the database, in the array mentioned above It will be the InPost Pay basket ID required for the next steps in the Postman app. Example of basket_id: 5b09XLhdhVnrYG5HwPitSKcIhPLWkAHy

  3. In the production scenario, the InPost Pay app on the mobile phone would display a push notification with a request to confirm basket pairing, which upon confirmation would result in the following request being sent to Magento:

    POST:
    https://lokalna.domena/rest/v1/izi/basket/5b09XLhdhVnrYG5HwPitSKcIhPLWkAHy/confirmation

    { "phone_number": { "country_prefix": "+48", "phone": "123123123" }, "masked_phone_number": "12*****23", "name": "Jan", "surname": "Kowalski", "browser": { "browser_trusted": true, "browser_id": "cd50a5b7-dcbf-4f2e-b6fd-5d10260e6235" }, "inpost_basket_id": "9cf1ff98-0f54-4931-9a86-27477f3e43b2", "status": "SUCCESS" }

Where the URL address contains the basket ID from the Magento database between "basket" and "confirmation". Therefore, in order to call basket confirmation in Postman, it is necessary to send the following request:

image-20240912-095346.png

The response will return all information about that Magento basket and the configuration of deliveries, consents, etc. received by InPost Pay. Example of a response from Magento:

{ "basket_id": "5b09XLhdhVnrYG5HwPitSKcIhPLWkAHy", "summary": { "basket_base_price": { "net": 26.02, "gross": 32, "vat": 5.98 }, "basket_final_price": { "net": 26.02, "gross": 32, "vat": 5.98 }, "basket_promo_price": { "net": 26.02, "gross": 32, "vat": 5.98 }, "currency": "PLN", "basket_additional_information": "", "payment_type": [ "PAY_BY_LINK", "GOOGLE_PAY", "APPLE_PAY", "CARD", "CARD_TOKEN", "BLIK_CODE", "BLIK_TOKEN" ], "basket_expiration_date": "2024-09-16T08:42:40Z" }, "delivery": [ { "delivery_type": "APM", "delivery_date": "2024-09-16T08:42:40Z", "delivery_options": [ { "delivery_name": "InPost Paczkomat® 24/7 - płatność przy odbiorze", "delivery_code_value": "COD", "delivery_option_price": { "net": 1.63, "gross": 2, "vat": 0.37 } } ], "delivery_price": { "net": 8.13, "gross": 10, "vat": 1.87 }, "free_delivery_minimum_gross_price": 50 }, { "delivery_type": "COURIER", "delivery_date": "2024-09-16T08:42:40Z", "delivery_options": [ ], "delivery_price": { "net": 12.2, "gross": 15, "vat": 2.8 }, "free_delivery_minimum_gross_price": 100 } ], "promo_codes": [ ], "products": [ { "product_id": "9", "product_category": "4", "ean": "24-WB02", "product_name": "Compete Track Tote", "product_description": "The Compete Track Tote holds a host of exercise supplies with ease. Stash your towel, jacket and street shoes inside. Tuck water bottles in easy-access external spaces. Perfect for trips to gym or yoga studio, with dual top handles for convenience to and from. Two-way zippers. Contrast detailing. W 22.0\" x H 17\" x D 10\". Kolumny/Wiersze Kolumna A Kolumna B Kolumna C Kolumna D Kolumna E Wiersz 1 A1 c C1 D1 E1 Wiersz 2 A2 B2 C2 D2 E2 Wiersz 3 A3 B3 C3 D3 E3 Wiersz 4 A4 B4 C4 D4 E4 Wiersz 5 A5 B5 C5 D5 E5 Wiersz 6 A6 B6 C6 D6 E6 Wiersz 7 A7 B7 C7 D7 E7 Wiersz 8 A8 B8 C8 D8 E8 Wiersz 9 A9 B9 C9 D9 E9 Wiersz 10 A10 B10 C10 D10 E10 Lista numeryczna punktów: Punkt pierwszy Punkt drugi Punkt trzeci Punkt czwarty Punkt piąty Punkt szósty Punkt siódmy Punkt ósmy Punkt dziewiąty Punkt dziesiąty Punktowanie: Punkt pierwszy Punkt drugi Punkt trzeci Punkt czwarty Punkt piąty Punkt szósty Punkt siódmy Punkt ósmy Punkt dziewiąty Punkt dziesiąty Pogrubiony tekst! Kursywa! Galeria Zdjęć: Kilka znaków specjalnych:", "product_link": "https://lokalna.domena/compete-track-tote.html", "product_image": "https://lokalna.domena/media/catalog/product/w/b/wb02-green-0.jpg", "base_price": { "net": 26.02, "gross": 32, "vat": 5.98 }, "promo_price": { "net": 26.02, "gross": 32, "vat": 5.98 }, "quantity": { "quantity": 1, "quantity_type": "INTEGER", "quantity_unit": "sztuk", "available_quantity": 80, "max_quantity": 80 }, "product_attributes": [ { "attribute_name": "Activity", "attribute_value": "Yoga, Gym, School" }, { "attribute_name": "Style", "attribute_value": "Exercise, Tote" }, { "attribute_name": "Material", "attribute_value": "Nylon, Polyester, Rayon" }, { "attribute_name": "Strap/Handle", "attribute_value": "Adjustable, Double, Shoulder" }, { "attribute_name": "Features", "attribute_value": "Waterproof, Lightweight, Reflective" } ], "delivery_product": [ { "delivery_type": "COURIER", "if_delivery_available": true }, { "delivery_type": "APM", "if_delivery_available": true } ] } ], "related_products": [ ], "consents": [ { "consent_id": "1", "consent_link": "https://lokalna.domena/regulamin.html", "consent_description": "Potwierdzam, że zapoznałam(em) się z treścią Regulaminu oraz akceptuję ich postanowienia.", "label_link": "", "additional_consent_links": [ ], "consent_version": "1", "requirement_type": "REQUIRED_ONCE" } ] }
  1. In the case of the production environment, clicking "Submit order" in the InPost Pay mobile app sends a request to Magento. In order to confirm orders on the local environment, it is necessary to simulate a corresponding request:

    POST:
    https://lokalna.domena/rest/v1/izi/order

    { "order_details": { "basket_id": "5b09XLhdhVnrYG5HwPitSKcIhPLWkAHy", "currency": "PLN", "basket_price": { "net": 34.15, "gross": 42.00, "vat": 7.85 }, "payment_type": "CARD" }, "account_info": { "name": "Jan", "surname": "Kowalski", "phone_number": { "country_prefix": "+48", "phone": "123123123" }, "mail": "jan.kowalski.inpostpaytest@example.com", "client_address": { "country_code": "PL", "city": "Warszawa", "address": "Testowa 123", "postal_code": "12-345", "address_details": { "building": null } } }, "delivery": { "delivery_type": "APM", "mail": "jan.kowalski.inpostpaytest@example.com", "phone_number": { "country_prefix": "+48", "phone": "123123123" }, "delivery_point": "KRA28M" }, "consents": [ { "consent_id": "1", "consent_version": "1", "is_accepted": true } ] }

In the above-mentioned example, it is necessary to modify:
basket_id ← inpost_pay_quote.basket_id value from the database mentioned above basket_price section ← it is necessary to provide the exact values returned by the previous query as the sum of: summary.basket_final_price and the price of the selected delivery method, i.e.: delivery.delivery_price for delivery_type: APM (i.e. parcel locker).

In the above-mentioned example, this would be the result:

... "basket_final_price": { "net": 26.02, "gross": 32, "vat": 5.98 }, ...

added to:

... "delivery": [ { "delivery_type": "APM", ... "delivery_price": { "net": 8.13, "gross": 10, "vat": 1.87 }, ...

resulting in the following:

{ "order_details": { ... "basket_price": { "net": 34.15, "gross": 42.00, "vat": 7.85 }, ... },

 

Note! These amounts are calculated by the InPost Pay app on the production environment, but for the purposes of the simulation you should calculate them on your own. If these amounts are miscalculated, the data provided is not correct or due to errors attributable to Magento the order is not placed, the cause of the foregoing should in the first place be sought in logs:

{katalog_magento2}/var/log/inpost-pay/2024-09-09.log (aktualna data)

If the order was placed correctly, Magento should respond as follows:

{ "order_details": { "basket_id": "5b09XLhdhVnrYG5HwPitSKcIhPLWkAHy", "order_id": "000000372", "order_discount": 0, "order_comments": "", "basket_price": { "net": 34.15, "gross": 42, "vat": 7.85 }, "currency": "PLN", "payment_type": "CARD", "pos_id": "V017960022", "order_creation_date": "2024-09-09T09:44:31Z", "order_merchant_status_description": "Złożone", "order_base_price": { "net": 26.02, "gross": 32, "vat": 5.98 }, "order_final_price": { "net": 34.15, "gross": 42, "vat": 7.85 }, "delivery_references_list": [] }, "invoice_details": { "legal_form": "PERSON", "country_code": "PL", "tax_id_prefix": "", "tax_id": "", "company_name": "", "name": "Jan", "surname": "Kowalski", "city": "Warszawa", "street": "Testowa 123", "building": "", "flat": "", "postal_code": "12-345", "mail": "jan.kowalski.inpostpaytest@example.com", "registration_data_edited": "", "additional_information": "" }, "account_info": { "name": "Jan", "surname": "Kowalski", "phone_number": { "country_prefix": "+48", "phone": "123123123" }, "mail": "jan.kowalski.inpostpaytest@example.com", "client_address": { "country_code": "PL", "address": "Testowa 123", "address_details": { "street": "Testowa 123", "building": "", "flat": "" }, "city": "Warszawa", "postal_code": "12-345" } }, "delivery": { "delivery_type": "APM", "delivery_codes": [], "delivery_date": "2024-09-16T09:44:34Z", "delivery_options": [], "delivery_price": { "net": 8.13, "gross": 10, "vat": 1.87 }, "mail": "jan.kowalski.inpostpaytest@example.com", "delivery_point": "KRA28M", "courier_note": "", "phone_number": { "country_prefix": "+48", "phone": "123123123" }, "delivery_address": { "name": "Jan Kowalski", "country_code": "PL", "address": "Testowa 123", "city": "Warszawa", "postal_code": "12-345", "address_details": { "street": "Testowa 123", "building": "", "flat": "" } } }, "consents": [ { "consent_id": "1", "consent_version": "1", "is_accepted": true } ], "products": [ { "product_id": "9", "product_category": "4", "ean": "24-WB02", "product_name": "Compete Track Tote", "product_description": "The Compete Track Tote holds a host of exercise supplies with ease. Stash your towel, jacket and street shoes inside. Tuck water bottles in easy-access external spaces. Perfect for trips to gym or yoga studio, with dual top handles for convenience to and from. Two-way zippers. Contrast detailing. W 22.0\" x H 17\" x D 10\". Kolumny/Wiersze Kolumna A Kolumna B Kolumna C Kolumna D Kolumna E Wiersz 1 A1 c C1 D1 E1 Wiersz 2 A2 B2 C2 D2 E2 Wiersz 3 A3 B3 C3 D3 E3 Wiersz 4 A4 B4 C4 D4 E4 Wiersz 5 A5 B5 C5 D5 E5 Wiersz 6 A6 B6 C6 D6 E6 Wiersz 7 A7 B7 C7 D7 E7 Wiersz 8 A8 B8 C8 D8 E8 Wiersz 9 A9 B9 C9 D9 E9 Wiersz 10 A10 B10 C10 D10 E10 Lista numeryczna punktów: Punkt pierwszy Punkt drugi Punkt trzeci Punkt czwarty Punkt piąty Punkt szósty Punkt siódmy Punkt ósmy Punkt dziewiąty Punkt dziesiąty Punktowanie: Punkt pierwszy Punkt drugi Punkt trzeci Punkt czwarty Punkt piąty Punkt szósty Punkt siódmy Punkt ósmy Punkt dziewiąty Punkt dziesiąty Pogrubiony tekst! Kursywa! Galeria Zdjęć: Kilka znaków specjalnych:", "product_link": "https://lokalna.domena/compete-track-tote.html", "product_image": "https://lokalna.domena/media/catalog/product/w/b/wb02-green-0.jpg", "base_price": { "net": 26.02, "gross": 32, "vat": 5.98 }, "quantity": { "quantity": 1, "quantity_type": "INTEGER", "quantity_unit": "sztuk", "available_quantity": 79, "max_quantity": 79 }, "product_attributes": [ { "attribute_name": "Activity", "attribute_value": "Yoga, Gym, School" }, { "attribute_name": "Style", "attribute_value": "Exercise, Tote" }, { "attribute_name": "Material", "attribute_value": "Nylon, Polyester, Rayon" }, { "attribute_name": "Strap/Handle", "attribute_value": "Adjustable, Double, Shoulder" }, { "attribute_name": "Features", "attribute_value": "Waterproof, Lightweight, Reflective" } ], "delivery_product": [ { "delivery_type": "COURIER", "if_delivery_available": true }, { "delivery_type": "APM", "if_delivery_available": true } ] } ] }