This article provides a quick guide to create payments.
Code sample
Once the user has selected their given payment option, you can begin the process
of creating a payment.For this step, you need to depend on IPaymentCreationService
(_paymentCreationService below) and your persistence layer (_orderStorageService below).
publicclassPaymentController:Controller{...[HttpPost]publicasyncTask<IActionResult>Index(<YOUR_PARAMETERS>){// Prepare the requestvarpaymentIdentifier=...;varshippingAddress=...;varbillingAddress=...;varorder=...;varcultureCode=...;// Create the order in your own persistence_orderStorageService.Create(paymentOrder);// Simple example here, normally you could be able to // get more information from the http method, http context etc.varsampleContext=newSampleContext(1);varrequest=newPaymentCreationRequest(paymentIdentifier,shippingAddress,billingAddress,order,cultureCode);try{varresponse=await_paymentCreationService.HandlePaymentAsync(sampleContext,request);returnresponseswitch{PaymentCreationRedirectResponseredirectResponse=>Redirect(redirectResponse.AbsoluteUrl),_=>BadRequest(),};}catch(PaymentExceptionex){returnBadRequest(ex.Message);}}}
The AbsoluteUrl returned in the redirect response will redirect the user to
the given payment provider's payment window.
Next step
Once the payment has been succesfully initiated, the user will be redirected to the
given payment window, finish their payment, and again be redirected back to your
webshop. In order to ensure payments are correctly authorized by a payment provider,
you must setup a controller which accepts callbacks.
This is covered in the next step here.