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.

  • Developer Manao 1 post 21 karma points
    Feb 18, 2015 @ 04:14
    Developer Manao
    0

    uCommerce - Integrating uCommerce with a Payment Provider

    Dear Support

    Now, I already Integrate uCommerce with a Payment Provider but I've some problem when we create payment I'm not found referenceId in payment, here is code:

     public Payment CreatePayment(PaymentRequest request)
     {
                PurchaseOrder order = request.PurchaseOrder;
    
                var payment = new Payment
                {
                    TransactionId = Guid.NewGuid().ToString(),
                    PaymentMethod = request.PaymentMethod,
                    PaymentMethodName = request.PaymentMethod.Name,
                    Created = DateTime.Now,
                    Fee = CalculatePaymentFee(request).Value,
                    FeePercentage = request.PaymentMethod.FeePercent,
                    PaymentStatus = PaymentStatus.Get((int)PaymentStatusCode.PendingAuthorization),
                    Amount = request.Amount.Value,
                    PurchaseOrder = order
                };
                return payment;
    }

    Thank you for help!!!
    Best regards,
    Paul

  • Morten Skjoldager 440 posts 1499 karma points
    Feb 18, 2015 @ 14:32
    Morten Skjoldager
    0

    Hello Paul, 

    ReferenceId can be set by the following:

            /// <summary>
            /// Creates a new payment fully initialized.
            /// </summary>
            /// <param name="request"></param>
            /// <returns></returns>
            public override Payment CreatePayment(PaymentRequest request)
            {
                var payment = base.CreatePayment(request);
                payment.ReferenceId = GetReferenceId(request);
                payment.PaymentStatus = PaymentStatus.Get((int)PaymentStatusCode.PendingAuthorization);
                payment.TransactionId = null;
                payment["paymentGuid"] = Guid.NewGuid().ToString();
                request.PurchaseOrder.AddPayment(payment);
                payment.Save();
                return payment;
            }
    
            /// <summary>
            /// Gets the reference id.
            /// </summary>
            /// <remarks>
            /// This is the OrderNumber of the <see cref="PurchaseOrder">purchase order</see> if set, else the order number series named "Default Payment Reference" is used for the reference id.
            /// </remarks>
            /// <param name="paymentRequest">The payment request.</param>
            /// <returns></returns>
            protected virtual string GetReferenceId(PaymentRequest paymentRequest)
            {
                string usedOrderId; // placeholder for the orderId used in this context.
                if (!string.IsNullOrEmpty(paymentRequest.PurchaseOrder.OrderNumber))
                    usedOrderId = paymentRequest.PurchaseOrder.OrderNumber;
                else
                {
                    var numberSeriesService = ObjectFactory.Instance.Resolve<INumberSeriesService>();
                    string orderNumber = numberSeriesService.GetNumber("Default Payment Reference");
                    usedOrderId = orderNumber;
                }
    
                return usedOrderId;
            }

    Above code is comming from ExternalPaymentMethodService which all our paymentproviders derrive from. So if you do the same thing, then you can just call base.CreatePayment, and then the referenceId should've been set. 

    Best regards

    Morten

Please Sign in or register to post replies

Write your reply to:

Draft