Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Matt Taylor 870 posts 2083 karma points
    May 12, 2022 @ 14:14
    Matt Taylor
    0

    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

  • Matt Brailsford 3741 posts 19764 karma points MVP 9x c-trib
    May 17, 2022 @ 08:16
    Matt Brailsford
    0

    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

  • Matt Taylor 870 posts 2083 karma points
    May 17, 2022 @ 08:39
    Matt Taylor
    0

    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

  • Matt Brailsford 3741 posts 19764 karma points MVP 9x c-trib
    May 17, 2022 @ 09:16
    Matt Brailsford
    100

    Hi Matt,

    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.

    Matt

  • Matt Taylor 870 posts 2083 karma points
    May 17, 2022 @ 11:06
    Matt Taylor
    0

    Thanks for that code, I think it will help me do what I want to.

    Cheers Matt.

  • Matt Taylor 870 posts 2083 karma points
    Jun 02, 2022 @ 14:25
    Matt Taylor
    0

    Thanks, this worked.

    var paymentMethod = TC.GetCurrentPaymentMethod(websiteRoot.Store);
    
    var paymentProviderAlias = paymentMethod.PaymentProviderAlias;
    
    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);
    
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft