What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hi everyone, anyone knows how to activate the multiple payments for a checkout? I'm sending two paym

U01UHQE5Z27
U01UHQE5Z27 Posts: 57 πŸ§‘πŸ»β€πŸš€ - Cadet

Hi everyone, anyone knows how to activate the multiple payments for a checkout?
I'm sending two payments in the checkout
"payments": [
{
"paymentMethodName": "efectivo",
"paymentProviderName": "Dupplo Payment",
"paymentSelection": "efectivo"
},
{
"paymentMethodName": "tarjeta",
"paymentProviderName": "Dupplo Payment",
"paymentSelection": "tarjeta"
}
],

But I'm getting this error:

{
"errors": [
{
"status": 400,
"code": "1107",
"detail": "Multiple payments are not allowed."
}
]
}

Any help will be appreciated, thanks

Comments

  • Eugenia Poidenko
    Eugenia Poidenko Sprykee Posts: 145 πŸ§‘πŸ»β€πŸš€ - Cadet

    For letting this request pass through, you need to unwire the SinglePaymentCheckoutRequestAttributesValidatorPlugin from the \Pyz\Glue\CheckoutRestApi\CheckoutRestApiDependencyProvider::getCheckoutRequestAttributesValidatorPlugins

  • U01UHQE5Z27
    U01UHQE5Z27 Posts: 57 πŸ§‘πŸ»β€πŸš€ - Cadet

    I'll try this, thanks

  • U01UHQE5Z27
    U01UHQE5Z27 Posts: 57 πŸ§‘πŸ»β€πŸš€ - Cadet

    Hi, did you know how to split the grand total between the two payments? because it's taking the total in the first payment and ignoring the second one.

  • Eugenia Poidenko
    Eugenia Poidenko Sprykee Posts: 145 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited February 2023

    Good morning @U01UHQE5Z27

    Splitting the order payment between two or more payment providers can be done at the Calculation step. You can have a look at the way spryker core manages the gift card payments: the GiftCardCalculatorPlugin creates and adds to quote a PaymentTransfer that has amount set. This amount is equal to the gift card value. The rest of the total (if any) will be payed by the second payment provider (PaymentCalculatorPlugin).

    This logic can be modified to suite any workflow the project needs. For example, you can choose to let customer select the amount he/she want to pay with each payment method (and accept the amount values from the API input). Another option will be to do a 50/50 split. This heavily depends on your project requirements.

  • U01UHQE5Z27
    U01UHQE5Z27 Posts: 57 πŸ§‘πŸ»β€πŸš€ - Cadet

    Hi, good morning, let me check this, thank you so much.

  • U01UHQE5Z27
    U01UHQE5Z27 Posts: 57 πŸ§‘πŸ»β€πŸš€ - Cadet

    Hi @UQKSAARKN I'm trying to do this ("and accept the amount values from the API input") as you commented, but I'm super lost and don't know how to change or make this possible, normally I use the CheckoutRestApi to place an order, this request get the payment in "RestPaymentTransfer" which does not have amount in the properties, how can I change and overrides this? Can you give some guidance please?

  • Eugenia Poidenko
    Eugenia Poidenko Sprykee Posts: 145 πŸ§‘πŸ»β€πŸš€ - Cadet

    Hi Daniel.

    Adding properties to the RestPaymentTransfer on the project level should work. If you do:

    <transfer name="RestPayment">
        <property name="amount" type="int" restRequestParameter="required"/>
    </transfer>
    

    It should allow you to accept one additional field in the data.attributes.payments.$index.amount.

    If this works, then check if the mapping of the REST attribute to the PaymentTransfer is correct in the \Spryker\Zed\PaymentsRestApi\Communication\Plugin\CheckoutRestApi\PaymentsQuoteMapperPlugin. Of course you want the automatic mapping to work, the property in the PaymentTransfer should be named the same:

    <transfer name="Payment">
        <property name="amount" type="int"/>
    </transfer>
    

    If you need to modify this (map to a different property in the QuoteTransfer, then you create an additional (or replacement) for the PaymentsQuoteMapperPlugin (implement \Spryker\Zed\CheckoutRestApiExtension\Dependency\Plugin\QuoteMapperPluginInterface and do whatever you need with the data in QuoteTransfer).

    Let me know if this helps πŸ™‚

  • U01UHQE5Z27
    U01UHQE5Z27 Posts: 57 πŸ§‘πŸ»β€πŸš€ - Cadet

    Thanks, let me try this

  • U01UHQE5Z27
    U01UHQE5Z27 Posts: 57 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited March 2023

    Hi @UQKSAARKN sorry to bother you, I made the changes and now I can set the amount for a payment, but still the checkout only takes 1 payment, do you have an idea what is happening?

    I removed the SinglePaymentCheckoutRequestAttributesValidatorPlugin.

    I'm sending two payments in the checkout

    In zed only one payment is persisted

  • U01UHQE5Z27
    U01UHQE5Z27 Posts: 57 πŸ§‘πŸ»β€πŸš€ - Cadet

    Orden in zed

  • Eugenia Poidenko
    Eugenia Poidenko Sprykee Posts: 145 πŸ§‘πŸ»β€πŸš€ - Cadet

    I can only help by asking questions here. Please bear with me.
    1. Does you payment data reach Zed layer? Are you able to debug this?
    2. Does you Payment provider implementation know how to handle two payments? Does each payment method know that it only needs to handle the amount it is assigned to handle? This is project level implementation because I do not recognize the payment method name you are using; this is why it’s difficult to say what is wrong exactly.

  • U01UHQE5Z27
    U01UHQE5Z27 Posts: 57 πŸ§‘πŸ»β€πŸš€ - Cadet

    Hi

    1. I don't know if both payment reach the Zed layer. I don't have my installation setup ready for debugging.
    2. I don't have any special implementarion on the payment providers, let me explain how we do this.
      We only load the two payments in payment-methods import.

    Then we assign these payment to the same OMS process and that's all, we don't implement nothing more, I tried assigning diferents OMS process for each payment but I got the same result.

  • Eugenia Poidenko
    Eugenia Poidenko Sprykee Posts: 145 πŸ§‘πŸ»β€πŸš€ - Cadet

    hi! There must be an implementation of a PSP handling underneath, otherwise your orders will not get anything but the payment provider and method name. You can look at what other PSP modules are doing for checkout in order to understand what your PSP needs.

    Form what I see in the code, all payment methods must be saved by the SalesPaymentCheckoutDoSaveOrderPlugin, so the another problem happens even earlier and your payments DO NOT reach Zed.

    This looks like there is need to debug the whole process.

  • U01UHQE5Z27
    U01UHQE5Z27 Posts: 57 πŸ§‘πŸ»β€πŸš€ - Cadet

    Thanks, I'm checking this right now, If I have more questions I'll let you know

  • U01UHQE5Z27
    U01UHQE5Z27 Posts: 57 πŸ§‘πŸ»β€πŸš€ - Cadet

    Hi Eugenia,

    I found this PaymentsQuoteMapperPlugin used in getQuoteMapperPlugin in CheckoutRestApiDependencyProvider

    This mapper has this code (see image)

    If I understand well, this code is taking only the first payment and ignore the rest, so this is my problem right?

  • Eugenia Poidenko
    Eugenia Poidenko Sprykee Posts: 145 πŸ§‘πŸ»β€πŸš€ - Cadet

    Yes, this looks like a mapping issue reason.

  • U01UHQE5Z27
    U01UHQE5Z27 Posts: 57 πŸ§‘πŸ»β€πŸš€ - Cadet

    Can I override this behaviour??

  • Eugenia Poidenko
    Eugenia Poidenko Sprykee Posts: 145 πŸ§‘πŸ»β€πŸš€ - Cadet

    You can replace the plugin. Unwire the one doing single payment and a new one.

  • U01UHQE5Z27
    U01UHQE5Z27 Posts: 57 πŸ§‘πŸ»β€πŸš€ - Cadet

    Ok, got it, thank you so much, and sorry for so much trouble xD

  • Eugenia Poidenko
    Eugenia Poidenko Sprykee Posts: 145 πŸ§‘πŸ»β€πŸš€ - Cadet

    No problem at all. It’s a pity there is so much time diff between us. I hope you get it working