I am trying to create a custom payment gateway by extending / adding it to Omnipay which is already implemented in Craft.
I have used the Ogone and other plugins as base, but I cant seem to get it working properly, probably because Klarna Checkout has quite a different flow than the ones I have tried to copy.
The flow I am trying to create:
- The user have a cart with items, he press pay / checkout
- On the payment page, he selects "Klarna Checkout" as payment option
- At this point, we need to give Klarna some information about the customer and the items / price he is going to pay for along with some credentials. If all information is correct, Klarna returns a snippet (payment form) as HTML.
- This snipped then needs to be embedded into the payment page (or redirected to a page that displays it).
- When the user has payed using this payment form, klarna will redirect the user to a predefined endpoint, where we need to tell him, and Craft that the order is payed for.
What I am having problems with is the plugin itself, I have done the initial setup, I can choose it as a payment option and the code runs, but we are having problems with the sendData() function in purchaseRequest.php
This function seems to send data to an endpoint, and get some response, but exactly what that response should be, I cant seem to find out. Since Klarna Checkout do not have an endpoint, but is a PHP class / a set of functions we have imported with Composer, we cant just send data directly to Klarna, but need to create a order request using this class, and that class will then contact Klarna to get the snippet (payment form).
What I am having trouble with is figuring out what this function needs, if we need to use it at all, and how to work around it to display the payment form to the end user.
Any nudge in the right direction would be greatly appreciated!