How to finalise an order without using GeneratePaymentForm?
My bookings website has been up and running for a few years now using Umbraco 7 and Tea Commerce 3.2.5.
I uses TC.GeneratePaymentForm to finalise the booking.
I'm now in the process of creating a WebAPI so that a 3rd party can make bookings through their own website.
How do I create an API function that will complete the transaction?
Currently I can only see GeneratePaymentForm for doing this and I'm not sure that will work via the API with no UI.
Are you basically wanting to bypass the payment provider and just mark the order as finalized? or are you trying to trigger the payment provider from an API endpoint and get redirected to the payment gateway?
In this particular case the built in 'Invoicing' payment method is being used so I don't need to go anywhere.
I just need a way to mark the order's payment status as 'Authorized' and whatever else normally happens to complete the order.
With further research I have found the Order.Finalize method so I suspect that is the way to do it but I have been struggling to figure out the correct way to call it with the CallbackInfo object in Tea Commerce 3.2.5.
There does not appear to be any docs for this part of the API.
Ok, well, these are most of the steps that get called during finalization from the Continue URL
Order order = GetOrder(storeId, orderId);
IPaymentProvider paymentProvider = PaymentProviderService.Instance.Get(paymentProviderAlias);
IDictionary<string, string> settings = PaymentMethodService.Instance.Get(order.StoreId, order.PaymentInformation.PaymentMethodId.Value).GetMergedSettings(order.LanguageId);
CallbackInfo callbackInfo = paymentProvider.ProcessCallback(order, HttpContext.Current.Request, settings);
if (callbackInfo != null)
{
order.Finalize(callbackInfo.AmountAuthorized, callbackInfo.TransactionId, callbackInfo.PaymentState, callbackInfo.PaymentType, callbackInfo.PaymentIdentifier);
}
SessionController.SetCurrentFinalizedOrderId(order.StoreId, order.Id);
string continueUrl = paymentProvider.GetContinueUrl(order, PaymentMethodService.Instance.Get(order.StoreId, order.PaymentInformation.PaymentMethodId.Value).GetMergedSettings(order.LanguageId));
if (!continueUrl.StartsWith("http"))
{
Uri baseUrl = new UriBuilder(HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port).Uri;
continueUrl = new Uri(baseUrl, continueUrl).AbsoluteUri;
}
HttpContext.Current.Response.Redirect(continueUrl);
This is just a code dump though as most of this is spread across multiple functions. Hopefully there is enough here though to piece together a solution.
How to finalise an order without using GeneratePaymentForm?
My bookings website has been up and running for a few years now using Umbraco 7 and Tea Commerce 3.2.5.
I uses TC.GeneratePaymentForm to finalise the booking.
I'm now in the process of creating a WebAPI so that a 3rd party can make bookings through their own website.
How do I create an API function that will complete the transaction? Currently I can only see GeneratePaymentForm for doing this and I'm not sure that will work via the API with no UI.
Thanks,
Matt
Hi Matt,
It kind of all depends.
Are you basically wanting to bypass the payment provider and just mark the order as finalized? or are you trying to trigger the payment provider from an API endpoint and get redirected to the payment gateway?
Matt
Hi Matt,
Thanks for the reply.
In this particular case the built in 'Invoicing' payment method is being used so I don't need to go anywhere.
I just need a way to mark the order's payment status as 'Authorized' and whatever else normally happens to complete the order.
With further research I have found the Order.Finalize method so I suspect that is the way to do it but I have been struggling to figure out the correct way to call it with the CallbackInfo object in Tea Commerce 3.2.5.
There does not appear to be any docs for this part of the API.
Thanks,
Matt
Hi Matt,
Ok, well, these are most of the steps that get called during finalization from the Continue URL
This is just a code dump though as most of this is spread across multiple functions. Hopefully there is enough here though to piece together a solution.
Matt
Thanks for that code, I think it will help me do what I want to.
Cheers Matt.
Thanks, this worked.
is working on a reply...