Start a new topic
Answered

Mutiple passes through ProcessPayment

When debugging I see that the ProcessPayment method of my custom payment method is being called two times. Is this normal, or have I messed up my installation somehow?


:Sigve


Best Answer

Oh, I see. Well, within payment method type of "Prepared form" your method will be called twice: the first time while creating order and primary processing payments (processing result info will be used for further decision - what to do next - to redirect customer, or to display payment form and so on) - you can find the call of OrderModuleProcessOrderPaymentsAsync at ApiCartController of Storefront solution, the second time - from CartController of Storefront solution - just before rendering HTML-form (it's necessary since the HTML-code of form can be received only in that way). So, you didn't mess up your installation - it's normal =).


Does your payment method require some kind of redirects to external payment systems (like PayPal checkout) with subsequent handling their callbacks?

I am using the PreparedForm type with Alternative group. The two passes of ProcessPayment happen before the prepared payment form is rendered.

   

 public override PaymentMethodType PaymentMethodType
        {
            get { return PaymentMethodType.PreparedForm; }
        }

        public override PaymentMethodGroupType PaymentMethodGroupType
        {
            get { return PaymentMethodGroupType.Alternative; }
        }

        public override ProcessPaymentResult ProcessPayment(ProcessPaymentEvaluationContext context)
        {
            var retVal = new ProcessPaymentResult();

After the prepared form, it seems to work as expected, going into validate payment and post process payment.


:Sigve   

Answer

Oh, I see. Well, within payment method type of "Prepared form" your method will be called twice: the first time while creating order and primary processing payments (processing result info will be used for further decision - what to do next - to redirect customer, or to display payment form and so on) - you can find the call of OrderModuleProcessOrderPaymentsAsync at ApiCartController of Storefront solution, the second time - from CartController of Storefront solution - just before rendering HTML-form (it's necessary since the HTML-code of form can be received only in that way). So, you didn't mess up your installation - it's normal =).

Thanks.

I better add some checks to my ProcessPayment so I do not create two payments in the remote payment system.


:Sigve

Login or Signup to post a comment