Copied to clipboard

Flag this post as spam?

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


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Cathy Pank 21 posts 41 karma points
    Apr 28, 2013 @ 01:54
    Cathy Pank
    0

    PayPal Direct Pay IPaymentMethodService usage Help

    uCommerce version 3.5.0.13098

    I have been implementing a Payment Service for the PayPal Direct Payment service and I am unable to work out how to return the payment status or error message back to the calling Razor script or add it to the purchase order so that the order is marked as paid. 

    I have tried various different ways of triggering the payment method service based on the various forum articles on here in order to get a response back to the page but the Payment returned is blank or the method is a void.

    My PaymentMethodService is able to connect to Paypal and process a payment sucessfully but I am not getting the payment back to update the order and cannot work out how to display the message back from PayPal if the card details are wrong etc..

    The main elements of the script are here: I have just removed the form items into the payment request:

    var basket = TransactionLibrary.GetBasket();
    PurchaseOrder order = basket.PurchaseOrder;
    
    /* [Build address]  */
    
    var shippingMethod = ShippingMethod.All().FirstOrDefault();
    var shipment = order.CreateShipment(shippingMethod, newShipmentAddress);
    // Add all order lines to shipment using a handy extension mehod in UCommerce.Extensions called ForEach
    order.OrderLines.ForEach(x => shipment.AddOrderLine(x));
    order.Save();
    
    int newPaymentMethodId;
    if (int.TryParse(HttpContext.Current.Request.Form["payment-method"], out newPaymentMethodId))
    {
        var paymentMethod = PaymentMethod.Get(newPaymentMethodId);
            var paymentRequest = new UCommerce.Transactions.Payments.PaymentRequest(order, paymentMethod, orderTotal);
    
            paymentRequest.AdditionalProperties.Add("CreditCardNumber", request.Form["CreditCardNumber"]);
        paymentRequest.AdditionalProperties.Add("CreditCardType", request.Form["CreditCardType"]);
            paymentRequest.AdditionalProperties.Add("CardExpiryYear", "20" + request.Form["CardExpiryYear"]);
            paymentRequest.AdditionalProperties.Add("CardExpiryMonth", request.Form["CardExpiryMonth"]);
            paymentRequest.AdditionalProperties.Add("CVV2", request.Form["CVV2"]);
    
            paymentRequest.AdditionalProperties.Add("IPNHandler", "http://" + HttpContext.Current.Request.Url.Host + "/paypal-ipn-handler/");

    The various ways I have tried are:

    TransactionLibrary.CreatePayment(newPaymentMethodId, -1, true, false);

    Nothing is returned (http://our.umbraco.org/projects/website-utilities/ucommerce/ucommerce-support/29925-step-by-step-Process-on-Ordering)

    var service = paymentMethod.GetPaymentMethodService();
    var paymentFactory = paymentMethod as IPaymentFactory;
    Payment thisPayment = paymentFactory.CreatePayment(paymentRequest);

    payment Factory is always null - so this doesnt submit to the payment service at all (After following http://our.umbraco.org/projects/website-utilities/ucommerce/ucommerce-support/34939-PayPal-payment )

    Payment paymentResult = paymentMethod.GetPaymentMethodService().RequestPayment(paymentRequest);

    This returns something but if I have a message back from paypal about a card issue I cannot work out how to receive the message back.

    The example paypal SDK code saves all the response data into the current context so I could do that but I must be missing something if I cannot just receive the payment and status back in order to do something useful with it

     

    HttpContext CurrContext = HttpContext.Current;
    CurrContext.Items.Add("Response_apiName", "GetTransactionDetails");
    CurrContext.Items.Add("Response_redirectURL", null);
    CurrContext.Items.Add("Response_requestPayload", service.getLastRequest());
    CurrContext.Items.Add("Response_responsePayload", service.getLastResponse());

    How am I supposed to call the service in order to get the correct data back to update the purchase order or if neccesary display the message to the user that the card has been declined.

    Thanks

     

  • Cathy Pank 21 posts 41 karma points
    Apr 30, 2013 @ 11:46
    Cathy Pank
    0

    If anyone finds this, my issue was mostly that examples I was following were a mixture of older UCommerce and older Umbraco versions combined with newer APIs. I was using UCommerce 3 and Umbraco 6 with Razor.

    In the end I just called :

    // Get the service
    IPaymentMethodService ppDirectService = paymentMethod.GetPaymentMethodService();
    
    // Request payment with eWAY
    Payment paymentReturn = ppDirectService.RequestPayment(paymentRequest);

    And made sure that my Payment Service always returned a valid payment object whether the payment was rejected or not.

    Following someone elses example, for any actual call errors I set the Transaction Id to -1. 

    catch (Exception ex)
    {
        Payment p = new Payment();
            p.TransactionId = "-1";
            p.PaymentStatus = new PaymentStatus();
            p.PaymentStatus.Name = ex.StackTrace;
            p["RESPMSG"] = "[" + ex.Message + "]" + ex.StackTrace;
            return p;
    }

    For situations where the PayPal API call were fine but the card declined I set the PaymentStatus.Name as FAILURE and passed the PayPal message through as a payment property.

    My only last thing is to set up a transalation table between the returned PayPal API statuses and the Ucommerce payment statuses. Unless anyone has one handy to pass on..

Please Sign in or register to post replies

Write your reply to:

Draft