We're currently implementing a new site, where we use VueJS for the frontend. I've created a service, which saves the order with the paymentmethod etc.
I'm missing what I need to do to return the form from the selected paymentmethod.
But how do I go about combining this with the right paymentform (like Paypal or something)? I'm now just returning the ContinueUrl.
I've got a GenerateForm for the paymentmethod, but I'm missing some kind of link. I guess... The missing link... For returning the needed GenerateForm.
Ok, well firstly, you probably shouldn't finalize the order at this point. You really should only call this once you have some kind of notification from payment gateway as once an order is finalized, there is no going back.
In terms of generating the HTML form to render, unfortunately we only currently have one way of doing this, which is by using the @Html.BeginPaymentForm helper which runs in a razor file.
You might be able to get the payment providers form definition by calling the paymentProvider.GenerateForm method, but you'd be responsible for converting that into an actual form.
To do this, you'd probably need to do something like
var paymentMethod = paymentMethodService.GetPaymentMethod(writableOrder.PaymentInfo.PaymentMethodId.Value);
var paymentProvider = paymentProviderService.GetPaymentProvider(paymentMethod.PaymentProviderAlias);
var settings = new ReadOnlyDictionary(translationService.TranslateValues(paymentMethod.PaymentProviderSettings, writableOrder.LanguageIsoCode));
var continueUrl = uriResolver.GetContinueUrl(paymentMethod.PaymentProviderAlias, orderReference, hashProvider);
var cancelUrl = uriResolver.GetCancelUrl(paymentMethod.PaymentProviderAlias, orderReference, hashProvider);
var callbackUrl = uriResolver.GetCallbackUrl(paymentMethod.PaymentProviderAlias, orderReference, hashProvider);
var formResult = paymentProvider.GenerateForm(writableOrder, continueUrl, cancelUrl, callbackUrl, settings);
This is ultimately what the Html.BeginPaymentForm helper does and then renders an MvcForm based on the formResult settings.
A few things to note though.
1) The Html.BeginPaymentForm method is generally also responsible for ensuring at the last minute that if there is a logged in member, that their member ID is assigned to the order. If you need this behavior, you'll have to implement this too.
2) The formResult object can also contain a MetaData property which it is expected that whatever is in this, is copied over to the order's properties collection so again you'll need to do this. This can be essential if the payment provider stores values in the order that it expects when it comes to finalize the order later.
You'r implementation for this should be something like
if (formResult.MetaData != null && formResult.MetaData.Count > 0)
{
writableOrder.SetProperties(formResult.MetaData
.ToDictionary(x => x.Key, x => new PropertyValue(x.Value, true, false)), SetBehavior.Merge);
}
As such, you may want to move your _vendrApi.SaveOrder(order); and uow.Compelte() to run AFTER this update.
We do need to make all this a bit nicer / easier for SPA usage but I need to put some time aside with some devs to discuss what this API would look like.
In the meantime you'll either need to do the above, or, look at doing something where you ajax load in a razor partial that actually calls Html.BeginPaymentForm.
Thanks, yeah, I'm moving that part to the webhook-callback.
While working on the webhook, I saw the OrderStatusCode was 'InconsistentPayment'. From there on, I changed the code and just set the right OrderStatusCode.
I think I'm fine now.
Returning paymentpage from ApiController
Hi Matt,
We're currently implementing a new site, where we use VueJS for the frontend. I've created a service, which saves the order with the paymentmethod etc. I'm missing what I need to do to return the form from the selected paymentmethod.
Right now I'm doing something like this:
But how do I go about combining this with the right paymentform (like Paypal or something)? I'm now just returning the ContinueUrl.
I've got a GenerateForm for the paymentmethod, but I'm missing some kind of link. I guess... The missing link... For returning the needed GenerateForm.
Hi Sibren,
Ok, well firstly, you probably shouldn't finalize the order at this point. You really should only call this once you have some kind of notification from payment gateway as once an order is finalized, there is no going back.
In terms of generating the HTML form to render, unfortunately we only currently have one way of doing this, which is by using the
@Html.BeginPaymentForm
helper which runs in a razor file.You might be able to get the payment providers form definition by calling the paymentProvider.GenerateForm method, but you'd be responsible for converting that into an actual form.
To do this, you'd probably need to do something like
This is ultimately what the
Html.BeginPaymentForm
helper does and then renders an MvcForm based on the formResult settings.A few things to note though.
1) The
Html.BeginPaymentForm
method is generally also responsible for ensuring at the last minute that if there is a logged in member, that their member ID is assigned to the order. If you need this behavior, you'll have to implement this too.2) The formResult object can also contain a
MetaData
property which it is expected that whatever is in this, is copied over to the order's properties collection so again you'll need to do this. This can be essential if the payment provider stores values in the order that it expects when it comes to finalize the order later.You'r implementation for this should be something like
As such, you may want to move your
_vendrApi.SaveOrder(order);
anduow.Compelte()
to run AFTER this update.We do need to make all this a bit nicer / easier for SPA usage but I need to put some time aside with some devs to discuss what this API would look like.
In the meantime you'll either need to do the above, or, look at doing something where you ajax load in a razor partial that actually calls
Html.BeginPaymentForm
.Hope this helps
Matt
Hi Matt,
Thank you, that did it!
However, when I have an invoice, it gets set as an error in Vendr 1.8:
Am I missing some required fields?
Hi Sibren,
As I said before, you shouldn't really be calling Finalize on the order at this point. This is the responsibility of the payment provider to do.
RE the order having an error state, what is the orders OrderStatusCode?
Matt
Hi Matt,
Thanks, yeah, I'm moving that part to the webhook-callback. While working on the webhook, I saw the OrderStatusCode was 'InconsistentPayment'. From there on, I changed the code and just set the right OrderStatusCode. I think I'm fine now.
Thanks for your help.
is working on a reply...