public async Task CanGetPaymentAction()
        {
            PaymentRequest <CardSource> paymentRequest  = TestHelper.CreateCardPaymentRequest();
            PaymentResponse             paymentResponse = await _api.Payments.RequestAsync(paymentRequest);

            IEnumerable <PaymentAction> actionsResponse = await _api.Payments.GetActionsAsync(paymentResponse.Payment.Id);

            actionsResponse.ShouldNotBeNull();
            actionsResponse.ShouldHaveSingleItem();

            PaymentProcessed payment       = paymentResponse.Payment;
            PaymentAction    paymentAction = actionsResponse.SingleOrDefault();

            paymentAction.ShouldNotBeNull();
            paymentAction.Id.ShouldBe(payment.ActionId);
            paymentAction.ProcessedOn.ShouldBeGreaterThanOrEqualTo(payment.ProcessedOn);
            paymentAction.Approved.ShouldBeTrue();
            paymentAction.Approved.ShouldBe(payment.Approved);
            paymentAction.ResponseCode.ShouldBe(payment.ResponseCode);
            paymentAction.ResponseSummary.ShouldBe(payment.ResponseSummary);
            paymentAction.Reference.ShouldBe(payment.Reference);
            paymentAction.AuthCode.ShouldBe(payment.AuthCode);
            paymentAction.Type.ShouldBe(ActionType.Authorization);
            paymentAction.Links.ShouldNotBeNull();
        }
        public async Task CanGetMultiplePaymentActions()
        {
            PaymentRequest <CardSource> paymentRequest  = TestHelper.CreateCardPaymentRequest();
            PaymentResponse             paymentResponse = await _api.Payments.RequestAsync(paymentRequest);

            var captureRequest = new CaptureRequest
            {
                Reference = Guid.NewGuid().ToString()
            };
            CaptureResponse captureResponse = await _api.Payments.CaptureAsync(paymentResponse.Payment.Id, captureRequest);

            IEnumerable <PaymentAction> actionsResponse = await _api.Payments.GetActionsAsync(paymentResponse.Payment.Id);

            actionsResponse.ShouldNotBeNull();

            PaymentAction authorizationPaymentAction = actionsResponse.SingleOrDefault(a => a.Type == ActionType.Authorization);

            authorizationPaymentAction.ShouldNotBeNull();
            authorizationPaymentAction.Id.ShouldBe(paymentResponse.Payment.ActionId);

            PaymentAction capturePaymentAction = actionsResponse.SingleOrDefault(a => a.Type == ActionType.Capture);

            capturePaymentAction.ShouldNotBeNull();
            capturePaymentAction.Id.ShouldBe(captureResponse.ActionId);
            capturePaymentAction.Reference.ShouldBe(captureResponse.Reference);
            capturePaymentAction.Links.ShouldNotBeNull();
        }
Ejemplo n.º 3
0
        protected void PaymentButton_Click(object sender, EventArgs e)
        {
            PaymentRequest paymentRequest = new PaymentRequest();
            decimal        amount;

            decimal.TryParse(lblTotal.Text, out amount);
            int cvc;

            int.TryParse(CVCText.Text, out cvc);
            paymentRequest.Amount      = amount;
            paymentRequest.CardName    = NameText.Text;
            paymentRequest.CardNumber  = NumberText.Text;
            paymentRequest.CVC         = cvc;
            paymentRequest.Description = "Test payment";
            paymentRequest.Expiry      = DateTime.Parse(ExpiryText.Text);
            PaymentAction payment = new PaymentAction(paymentRequest);

            payment.StartPayment();
            if (paymentRequest != null)
            {
                Response.Redirect("~/Checkout/CheckoutError.aspx");
            }
            else
            {
                Session["ActivePayment"] = payment;
                Response.Redirect("~/Checkout/CheckoutComplete.aspx");
            }
        }
        public void ValidatePayment(ShopifyOrder order, PaymentAction action)
        {
            action.Validation = new ValidationResult();

            var transaction = order
                              .ShopifyTransactions.FirstOrDefault(x => x.ShopifyTransactionId == action.ShopifyTransactionId);

            //if (transaction == null)
            //{
            //    return;
            //}

            if (action.ActionCode == ActionCode.CreateInAcumatica)
            {
                action.Validation = ReadyToCreatePayment(transaction);
                return;
            }

            if (action.ActionCode == ActionCode.UpdateInAcumatica)
            {
                action.Validation = ReadyToUpdatePayment(transaction);
                return;
            }

            if (action.ActionCode == ActionCode.ReleaseInAcumatica)
            {
                action.Validation = ReadyToRelease(transaction);
                return;
            }
        }
Ejemplo n.º 5
0
        public ActionResult DeleteConfirmed(int id)
        {
            PaymentAction paymentAction = db.PaymentActions.Find(id);

            db.PaymentActions.Remove(paymentAction);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 6
0
        public IPaymentResponse DoExpressCheckoutPayment(OrderDetails orderDetails, string payPalToken, string payPalPayerId, PaymentAction action)
        {
            if (orderDetails == null) throw new ArgumentNullException("orderDetails");
            if (string.IsNullOrWhiteSpace(payPalToken)) throw new ArgumentNullException("payPalToken");
            if (string.IsNullOrWhiteSpace(payPalPayerId)) throw new ArgumentNullException("payPalPayerId");

            var request = _requestBuilder.DoExpressCheckoutPayment(orderDetails, payPalToken, payPalPayerId);
            return doExpressCheckoutPaymentFor(request);
        }
Ejemplo n.º 7
0
        public IPaymentResponse DoExpressCheckoutPayment(decimal amount, CurrencyCodeType currencyCodeType, string payPalToken, string payPalPayerId, PaymentAction action)
        {
            if (amount <= 0) throw new ArgumentOutOfRangeException("amount", "Amount must be greater than zero.");
            if (string.IsNullOrWhiteSpace(payPalToken)) throw new ArgumentNullException("payPalToken");
            if (string.IsNullOrWhiteSpace(payPalPayerId)) throw new ArgumentNullException("payPalPayerId");

            var request = _requestBuilder.DoExpressCheckoutPayment(amount,currencyCodeType, payPalToken, payPalPayerId,action);
            return doExpressCheckoutPaymentFor(request);
        }
 private void ProcessTransactionRelease(PaymentAction status)
 {
     if (status.ActionCode == ActionCode.ReleaseInAcumatica && status.IsValid)
     {
         var transaction
             = _syncOrderRepository
               .RetrieveShopifyTransactionWithNoTracking(status.ShopifyTransactionId);
         _logService.Log(LogBuilder.ReleasingTransaction(transaction));
         PushPaymentReleaseAndUpdateSync(transaction);
     }
 }
Ejemplo n.º 9
0
 public ActionResult Edit([Bind(Include = "PaymentActionID,PaymentActionCode,PaymentActionCodeDescription,PaymentTypeID,CodeStatus")] PaymentAction paymentAction)
 {
     if (ModelState.IsValid)
     {
         db.Entry(paymentAction).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PaymentTypeID = new SelectList(db.PaymentTypes, "PaymentTypeID", "PaymentCode", paymentAction.PaymentTypeID);
     return(View(paymentAction));
 }
Ejemplo n.º 10
0
        // See ITransactionRegister for parameter descriptions
        public DoExpressCheckoutPaymentRequest(string token, string payerId, string currencyCode, decimal amount)
        {
            base.method        = RequestType.DoExpressCheckoutPayment;
            this.paymentAction = PaymentAction.Sale;

            this.token   = token;
            this.payerId = payerId;

            this.currencyCode = currencyCode;
            this.amount       = amount;
        }
Ejemplo n.º 11
0
 public NameValueCollection DoExpressCheckoutPayment(decimal amount, CurrencyCodeType currencyCodeType, string payPalToken, string payPalPayerId, PaymentAction action)
 {
     var request = getQueryWithCredentials();
     request["METHOD"] = "DoExpressCheckoutPayment";
     request["TOKEN"] = payPalToken;
     request["PAYERID"] = payPalPayerId;
     request["PAYMENTREQUEST_0_AMT"] = amount.ToString("0.00");
     request["PAYMENTREQUEST_0_CURRENCYCODE"] = currencyCodeType.ToString();
     request["PAYMENTREQUEST_0_PAYMENTACTION"] = action.ToString();
     return request;
 }
        // See ITransactionRegister for parameter descriptions
        public DoExpressCheckoutPaymentRequest(string token, string payerId, string currencyCode, decimal amount)
        {
            base.method = RequestType.DoExpressCheckoutPayment;
            this.paymentAction = PaymentAction.Sale;

            this.token = token;
            this.payerId = payerId;

            this.currencyCode = currencyCode;
            this.amount = amount;
        }
Ejemplo n.º 13
0
        private List <PaymentAction> BuildRefundPaymentActions(ShopifyOrder orderRecord)
        {
            var output = new List <PaymentAction>();

            foreach (var refundTrans in orderRecord.RefundTransactions())
            {
                var refundAction = new PaymentAction();

                refundAction.ShopifyTransactionId = refundTrans.ShopifyTransactionId;
                refundAction.TransDesc            = $"Shopify Refund ({refundTrans.ShopifyTransactionId})";
                refundAction.PaymentGateway       = refundTrans.ShopifyGateway;
                refundAction.Amount = refundTrans.ShopifyAmount;

                var refund = orderRecord.Refund(refundTrans.ShopifyRefundId.Value);

                refundAction.HasShipping = refund.HasShipping();
                refundAction.Shipping    = refund.Shipping;
                refundAction.ShippingTax = refund.ShippingTax;

                refundAction.ActionCode = ActionCode.None;

                if (!refundTrans.ExistsInAcumatica())
                {
                    refundAction.ActionCode = ActionCode.CreateInAcumatica;
                }

                if (refundTrans.ExistsInAcumatica())
                {
                    refundAction.AcumaticaPaymentRef = refundTrans.AcumaticaPayment.AcumaticaRefNbr;
                    refundAction.AcumaticaHref
                        = _acumaticaUrlService.AcumaticaPaymentUrl(
                              PaymentType.CustomerRefund, refundTrans.AcumaticaPayment.AcumaticaRefNbr);
                }

                if (refundTrans.ExistsInAcumatica() &&
                    !refundTrans.AcumaticaPayment.NeedManualApply &&
                    !refundTrans.IsReleased())
                {
                    refundAction.ActionCode = ActionCode.ReleaseInAcumatica;
                }

                if (refundTrans.ExistsInAcumatica() &&
                    refundTrans.AcumaticaPayment.NeedManualApply)
                {
                    refundAction.ActionCode = ActionCode.NeedManualApply;
                }

                output.Add(refundAction);
            }

            return(output);
        }
Ejemplo n.º 14
0
        // See ITransactionRegister for parameter descriptions
        public SetExpressCheckoutRequest(string currencyCode, decimal totalAmount, string paymentDescription, string trackingReference, string serverURL, List<ExpressCheckoutItem> purchaseItems = null, string userEmail = null)
        {
            base.method = RequestType.SetExpressCheckout;
            this.paymentAction = PaymentAction.Sale;

            this.currencyCode = currencyCode;
            this.totalAmount = totalAmount;
            this.paymentDescription = paymentDescription;
            this.trackingReference = trackingReference;

            this.serverURL = serverURL;
            this.items = purchaseItems;
            this.email = userEmail;
        }
        protected string DoPayment(Payment payment, NameValueCollection details)
        {
            IDictionary <string, string> values = new Dictionary <string, string>();

            // Set up call
            values.Add("USER", payment.PaymentMethod.DynamicProperty <string>().ApiUsername);
            values.Add("PWD", payment.PaymentMethod.DynamicProperty <string>().ApiPassword);
            values.Add("SIGNATURE", payment.PaymentMethod.DynamicProperty <string>().ApiSignature);
            values.Add("METHOD", "DoExpressCheckoutPayment");
            values.Add("VERSION", "98.0");

            string[] fieldsToCopy = { "TOKEN", "PAYERID", "PAYMENTREQUEST_0_CURRENCYCODE", "PAYMENTREQUEST_0_AMT" };
            foreach (string key in details)
            {
                if (fieldsToCopy.Contains(key))
                {
                    values.Add(key, details[key]);
                }
            }

            PaymentAction pa = EnumExtensions.ParsePaymentActionThrowExceptionOnFailure(payment.PaymentMethod.DynamicProperty <string>().PaymentAction);

            values.Add("PAYMENTREQUEST_0_PAYMENTACTION", pa.ToString());

            LogAuditTrail(payment.PurchaseOrder, "DoExpressCheckoutPayment", values);
            var    post     = new HttpPost(GetPostUrl(payment.PaymentMethod), values);
            string response = post.GetString();

            NameValueCollection responseValues = HttpUtility.ParseQueryString(response);

            LogAuditTrail(payment.PurchaseOrder, "DoExpressCheckoutPaymentResponse", responseValues);
            if (responseValues["ACK"] != "Success")
            {
                throw new Exception(response);
            }

            var responseAmount = responseValues["PAYMENTINFO_0_AMT"];

            CheckReceivedAmountAgainstExpectedValue(payment.Amount, responseAmount, response);

            string responseCurrency = responseValues["PAYMENTINFO_0_CURRENCYCODE"];

            if (payment.PurchaseOrder.BillingCurrency.ISOCode != responseCurrency)
            {
                string message = string.Format("Wrong currency. Expected {0}, but was {1}", payment.PurchaseOrder.BillingCurrency.ISOCode, responseCurrency);
                throw new Exception(message + " - " + response);
            }

            return(responseValues["PAYMENTINFO_0_TRANSACTIONID"]);
        }
        protected virtual IDictionary <string, string> GetParameters(PaymentRequest paymentRequest)
        {
            var currency = paymentRequest.Amount.CurrencyIsoCode;
            // For dynamics, we have to call the extension method as a normal method.
            ReturnMethod rm =
                EnumExtensions.ParseReturnMethodThrowExceptionOnFailure(paymentRequest.PaymentMethod
                                                                        .DynamicProperty <string>().ReturnMethod);
            PaymentAction pa =
                EnumExtensions.ParsePaymentActionThrowExceptionOnFailure(paymentRequest.PaymentMethod
                                                                         .DynamicProperty <string>().PaymentAction);

            var dict = new Dictionary <string, string>
            {
                { "upload", "1" },
                { "cmd", "_cart" },
                { "business", paymentRequest.PaymentMethod.DynamicProperty <string>().Business },
                {
                    "return",
                    new Uri(AbsoluteUrlService.GetAbsoluteUrl(paymentRequest.PaymentMethod.DynamicProperty <string>()
                                                              .Return))
                    .AddOrderGuidParameter(
                        paymentRequest.Payment.PurchaseOrder).ToString()
                },
                { "rm", ((int)rm).ToString() },
                // Vendor code to identify Ucommerce
                { "bn", "Ucommerce_SP" },
                { "currency_code", currency },
                { "no_shipping", "1" },
                { "paymentaction", pa.ToString().ToLower() },
                {
                    "cancel_return",
                    AbsoluteUrlService.GetAbsoluteUrl(paymentRequest.PaymentMethod.DynamicProperty <string>()
                                                      .CancelReturn)
                },
                {
                    "notify_url",
                    CallbackUrl.GetCallbackUrl(paymentRequest.PaymentMethod.DynamicProperty <string>().NotifyUrl,
                                               paymentRequest.Payment)
                },
                { "invoice", paymentRequest.Payment.ReferenceId },
                {
                    "item_name_1",
                    string.Join(", ", paymentRequest.Payment.PurchaseOrder.OrderLines.Select(x => x.ProductName))
                },
                { "amount_1", paymentRequest.Payment.Amount.ToInvariantString() },
                { "quantity_1", "1" }
            };

            return(dict);
        }
Ejemplo n.º 17
0
        private PaymentAction BuildPaymentActions(ShopifyOrder orderRecord)
        {
            var paymentAction = new PaymentAction();

            paymentAction.ActionCode = ActionCode.None;
            paymentAction.Validation = new ValidationResult();

            if (orderRecord.HasPayment())
            {
                var payment = orderRecord.PaymentTransaction();
                paymentAction.ShopifyTransactionId = payment.ShopifyTransactionId;
                paymentAction.TransDesc            = $"Shopify Payment ({payment.ShopifyTransactionId})";
                paymentAction.PaymentGateway       = payment.ShopifyGateway;
                paymentAction.Amount = payment.ShopifyAmount;

                paymentAction.ActionCode = ActionCode.None;

                if (!payment.ExistsInAcumatica())
                {
                    paymentAction.ActionCode = ActionCode.CreateInAcumatica;
                }

                if (payment.ExistsInAcumatica())
                {
                    paymentAction.AcumaticaPaymentRef = payment.AcumaticaPayment.AcumaticaRefNbr;
                    paymentAction.AcumaticaHref
                        = _acumaticaUrlService.AcumaticaPaymentUrl(
                              PaymentType.Payment, payment.AcumaticaPayment.AcumaticaRefNbr);

                    if (orderRecord.OriginalPaymentNeedsUpdateForRefund())
                    {
                        paymentAction.ActionCode = ActionCode.UpdateInAcumatica;
                    }
                    else if (payment.ExistsInAcumatica() && payment.AcumaticaPayment.NeedRelease)
                    {
                        paymentAction.ActionCode = ActionCode.ReleaseInAcumatica;
                    }
                }
            }
            else
            {
                paymentAction.ShopifyTransactionId = -1;
                paymentAction.TransDesc            = $"Shopify Payment not found yet";
                paymentAction.PaymentGateway       = "No Gateway";
                paymentAction.Amount     = 0.00m;
                paymentAction.ActionCode = ActionCode.None;
            }

            return(paymentAction);
        }
Ejemplo n.º 18
0
        // See ITransactionRegister for parameter descriptions
        public SetExpressCheckoutRequest(string currencyCode, decimal totalAmount, string paymentDescription, string trackingReference, string serverURL, List <ExpressCheckoutItem> purchaseItems = null, string userEmail = null)
        {
            base.method        = RequestType.SetExpressCheckout;
            this.paymentAction = PaymentAction.Sale;

            this.currencyCode       = currencyCode;
            this.totalAmount        = totalAmount;
            this.paymentDescription = paymentDescription;
            this.trackingReference  = trackingReference;

            this.serverURL = serverURL;
            this.items     = purchaseItems;
            this.email     = userEmail;
        }
Ejemplo n.º 19
0
        // GET: PaymentActions/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PaymentAction paymentAction = db.PaymentActions.Find(id);

            if (paymentAction == null)
            {
                return(HttpNotFound());
            }
            return(View(paymentAction));
        }
Ejemplo n.º 20
0
        // GET: PaymentActions/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PaymentAction paymentAction = db.PaymentActions.Find(id);

            if (paymentAction == null)
            {
                return(HttpNotFound());
            }
            ViewBag.PaymentTypeID = new SelectList(db.PaymentTypes, "PaymentTypeID", "PaymentCode", paymentAction.PaymentTypeID);
            return(View(paymentAction));
        }
        // See ITransactionRegister for parameter descriptions
        public SetExpressCheckoutRequest(string currencyCode, decimal totalAmount, string paymentDescription, string trackingReference, string serverURL, List <ExpressCheckoutItem> purchaseItems = null, string userEmail = null)
        {
            base.method         = RequestType.SetExpressCheckout;
            this.landingpage    = "Billing";
            this.solutiontype   = "Sole";
            this.usercreditcard = "CreditCard";
            this.locatecode     = "us";
            this.paymentAction  = PaymentAction.Sale;

            this.currencyCode       = currencyCode;
            this.totalAmount        = totalAmount;
            this.paymentDescription = paymentDescription;
            this.trackingReference  = trackingReference;

            this.serverURL = serverURL;
            this.items     = purchaseItems;
            this.email     = userEmail;
        }
        public void ValidateRefundPayment(ShopifyOrder order, PaymentAction action)
        {
            var transaction = order
                              .ShopifyTransactions
                              .First(x => x.ShopifyTransactionId == action.ShopifyTransactionId);

            action.Validation = new ValidationResult();

            if (action.ActionCode == ActionCode.CreateInAcumatica)
            {
                action.Validation = ReadyToCreateRefundPayment(transaction);
            }

            if (action.ActionCode == ActionCode.ReleaseInAcumatica)
            {
                action.Validation = ReadyToReleaseRefundPayment(transaction);
            }
        }
        public async Task CanGetPaymentActionMetadata()
        {
            PaymentRequest <CardSource> paymentRequest = TestHelper.CreateCardPaymentRequest();
            var metadata = new KeyValuePair <string, object>("test", "1234");

            paymentRequest.Metadata.Add(metadata.Key, metadata.Value);
            PaymentResponse paymentResponse = await _api.Payments.RequestAsync(paymentRequest);

            IEnumerable <PaymentAction> actionsResponse = await _api.Payments.GetActionsAsync(paymentResponse.Payment.Id);

            actionsResponse.ShouldNotBeNull();

            PaymentAction paymentAction = actionsResponse.FirstOrDefault();

            paymentAction.ShouldNotBeNull();
            paymentAction.Metadata.ShouldNotBeNull();
            paymentAction.Metadata.ShouldNotBeEmpty();
            paymentAction.Metadata.ShouldHaveSingleItem();
            paymentAction.Metadata.ShouldContain(d => d.Key == metadata.Key && d.Value.Equals(metadata.Value));
        }
Ejemplo n.º 24
0
        protected void PaymentButton_Click(object sender, EventArgs e)
        {
            PaymentRequest paymentRequest = new PaymentRequest();
            decimal        amount;

            decimal.TryParse(AmountText.Text, out amount);
            int cvc;

            int.TryParse(CVCText.Text, out cvc);
            paymentRequest.Amount      = amount;
            paymentRequest.CardName    = NameText.Text;
            paymentRequest.CardNumber  = NumberText.Text;
            paymentRequest.CVC         = cvc;
            paymentRequest.Description = "Test payment";
            paymentRequest.Expiry      = DateTime.Parse(ExpiryText.Text);
            PaymentAction payment = new PaymentAction(paymentRequest);

            payment.StartPayment();
            Session["ActivePayment"] = payment;
            Response.Redirect("Thankyou.aspx");
        }
        private void ProcessRefundTransaction(PaymentAction refundAction)
        {
            if (refundAction.ActionCode == ActionCode.None)
            {
                return;
            }

            if (refundAction.ActionCode == ActionCode.CreateInAcumatica && refundAction.IsValid)
            {
                // Create Acumatica Refund payload
                //
                var transaction =
                    _syncOrderRepository
                    .RetrieveShopifyTransactionWithNoTracking(refundAction.ShopifyTransactionId);

                var refundWrite = BuildCustomerRefund(transaction);

                // Push to Acumatica and write Sync Record
                //
                _logService.Log(LogBuilder.CreateAcumaticaPayment(transaction));
                PushPaymentAndWriteSync(transaction, refundWrite);
            }
        }
 public DoExpressCheckoutPaymentOperation(ExpressCheckoutApi ec, string token, string payerid, double valor, PaymentAction action)
     : base(ec)
 {
     RequestNVP.Method        = "DoExpressCheckoutPayment";
     Token                    = token;
     PayerId                  = payerid;
     PaymentRequest(0).Amount = valor;
     PaymentRequest(0).Action = action;
 }
Ejemplo n.º 27
0
        public IPaymentResponse DoExpressCheckoutPayment(decimal amount, CurrencyCodeType currencyCodeType, string payPalToken, string payPalPayerId, PaymentAction action)
        {
            if (amount <= 0)
            {
                throw new ArgumentOutOfRangeException("amount", "Amount must be greater than zero.");
            }
            if (string.IsNullOrWhiteSpace(payPalToken))
            {
                throw new ArgumentNullException("payPalToken");
            }
            if (string.IsNullOrWhiteSpace(payPalPayerId))
            {
                throw new ArgumentNullException("payPalPayerId");
            }

            var request = _requestBuilder.DoExpressCheckoutPayment(amount, currencyCodeType, payPalToken, payPalPayerId, action);

            return(doExpressCheckoutPaymentFor(request));
        }
Ejemplo n.º 28
0
        public IPaymentResponse DoExpressCheckoutPayment(OrderDetails orderDetails, string payPalToken, string payPalPayerId, PaymentAction action)
        {
            if (orderDetails == null)
            {
                throw new ArgumentNullException("orderDetails");
            }
            if (string.IsNullOrWhiteSpace(payPalToken))
            {
                throw new ArgumentNullException("payPalToken");
            }
            if (string.IsNullOrWhiteSpace(payPalPayerId))
            {
                throw new ArgumentNullException("payPalPayerId");
            }

            var request = _requestBuilder.DoExpressCheckoutPayment(orderDetails, payPalToken, payPalPayerId);

            return(doExpressCheckoutPaymentFor(request));
        }
Ejemplo n.º 29
0
        public void OrderTests_Test4()
        {
            var       createdCart = CartFactory.GetOrCreateCart(AnonShopperMsgHandler);
            const int index       = 0;
            var       product     = ProductFactory.GetProducts(AnonShopperMsgHandler, index, 13).Items.First();
            const int itemQty     = 1;
            var       item        = CartItemFactory.AddItemToCart(AnonShopperMsgHandler,
                                                                  new CartItem
            {
                Product =
                    new Product
                {
                    ProductCode = product.ProductCode
                },
                Quantity = itemQty
            });
            var order   = OrderFactory.CreateOrderFromCart(AnonShopperMsgHandler, createdCart.Id);
            var billing = BillingInfoFactory.SetBillingInfo(AnonShopperMsgHandler, new BillingInfo()
            {
                PaymentType    = "Check",
                BillingContact = new Mozu.Api.Contracts.Core.Contact
                {
                    Address = new Address
                    {
                        Address1        = string.Format("{0} {1}", Generator.RandomString(8, Generator.RandomCharacterGroup.NumericOnly), Generator.RandomString(75, Generator.RandomCharacterGroup.AlphaNumericOnly)),
                        Address2        = Generator.RandomString(50, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        Address3        = Generator.RandomString(20, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        Address4        = Generator.RandomString(15, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        CityOrTown      = Generator.RandomString(25, Generator.RandomCharacterGroup.AlphaOnly),
                        CountryCode     = "US",
                        PostalOrZipCode = "78713",
                        StateOrProvince = "TX"
                    },
                    CompanyOrOrganization = Generator.RandomString(50, Generator.RandomCharacterGroup.AlphaNumericOnly),
                    Email               = Generator.RandomEmailAddress(),
                    FirstName           = Generator.RandomString(15, Generator.RandomCharacterGroup.AlphaOnly),
                    MiddleNameOrInitial = Generator.RandomString(1, Generator.RandomCharacterGroup.AlphaOnly),
                    LastNameOrSurname   = Generator.RandomString(35, Generator.RandomCharacterGroup.AlphaOnly),
                    PhoneNumbers        = new Mozu.Api.Contracts.Core.Phone
                    {
                        Home = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly)),
                        Mobile = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                               Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                               Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly)),
                        Work = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly))
                    }
                },
                IsSameBillingShippingAddress = true
            }, order.Id);

            var shipping = FulfillmentInfoFactory.SetFulFillmentInfo(AnonShopperMsgHandler, new FulfillmentInfo()
            {
                IsDestinationCommercial = false,
                FulfillmentContact      = new Mozu.Api.Contracts.Core.Contact
                {
                    Address = new Address
                    {
                        Address1        = string.Format("{0} {1}", Generator.RandomString(8, Generator.RandomCharacterGroup.NumericOnly), Generator.RandomString(75, Generator.RandomCharacterGroup.AlphaNumericOnly)),
                        Address2        = Generator.RandomString(50, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        Address3        = Generator.RandomString(20, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        Address4        = Generator.RandomString(15, Generator.RandomCharacterGroup.AlphaNumericOnly),
                        CityOrTown      = Generator.RandomString(25, Generator.RandomCharacterGroup.AlphaOnly),
                        CountryCode     = "US",
                        PostalOrZipCode = "78713",
                        StateOrProvince = "TX"
                    },
                    CompanyOrOrganization = Generator.RandomString(50, Generator.RandomCharacterGroup.AlphaNumericOnly),
                    Email               = Generator.RandomEmailAddress(),
                    FirstName           = Generator.RandomString(15, Generator.RandomCharacterGroup.AlphaOnly),
                    MiddleNameOrInitial = Generator.RandomString(1, Generator.RandomCharacterGroup.AlphaOnly),
                    LastNameOrSurname   = Generator.RandomString(35, Generator.RandomCharacterGroup.AlphaOnly),
                    PhoneNumbers        = new Mozu.Api.Contracts.Core.Phone
                    {
                        Home = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly)),
                        Mobile = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                               Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                               Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly)),
                        Work = string.Format("{0}-{1}-{2}", Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(3, Generator.RandomCharacterGroup.NumericOnly),
                                             Generator.RandomString(4, Generator.RandomCharacterGroup.NumericOnly))
                    }
                },
                ShippingMethodCode = "CUSTOM_FLAT_RATE_PER_ORDER_EXACT_AMOUNT",
                ShippingMethodName = "Flat Rate"
            }, order.Id);
            var getOrderActions = OrderFactory.GetAvailableActions(ApiMsgHandler, order.Id);

            Assert.AreEqual(getOrderActions.Count, 1);
            Assert.IsTrue(getOrderActions[0].Equals("SubmitOrder"));
            var status = OrderFactory.PerformOrderAction(AnonShopperMsgHandler, new OrderAction()
            {
                ActionName = "SubmitOrder"
            }, order.Id);
            var getOrder          = OrderFactory.GetOrder(ApiMsgHandler, order.Id);
            var getPaymentActions = PaymentFactory.GetAvailablePaymentActions(ApiMsgHandler, order.Id, getOrder.Payments[0].Id);

            Assert.AreEqual(getPaymentActions.Count, 3);
            Assert.IsTrue(getPaymentActions[0].Equals("ApplyCheck") || getPaymentActions[0].Equals("VoidPayment") || getPaymentActions[0].Equals("DeclinePayment"));
            Assert.IsTrue(getPaymentActions[1].Equals("ApplyCheck") || getPaymentActions[1].Equals("VoidPayment") || getPaymentActions[1].Equals("DeclinePayment"));
            Assert.IsTrue(getPaymentActions[2].Equals("ApplyCheck") || getPaymentActions[2].Equals("VoidPayment") || getPaymentActions[2].Equals("DeclinePayment"));
            var paymentAction = new PaymentAction()
            {
                ActionName  = "ApplyCheck",
                CheckNumber = "12345",
                Amount      = Convert.ToDecimal(getOrder.Total)
            };
            var orderPayment1 = PaymentFactory.PerformPaymentAction(ApiMsgHandler, paymentAction, order.Id, getOrder.Payments[0].Id);

            Assert.AreEqual(orderPayment1.PaymentStatus, "Paid");
            Assert.AreEqual(orderPayment1.Payments[0].Status, "Collected");
            Assert.AreEqual(orderPayment1.Payments[0].AmountCollected, getOrder.Total);
            Assert.AreEqual(orderPayment1.Payments[0].Interactions.Count, 2);
            Assert.IsTrue(orderPayment1.Payments[0].Interactions[1].Status.Equals("Captured"));
            Assert.IsTrue(orderPayment1.Payments[0].Interactions[1].InteractionType.Equals("ApplyCheck"));
            Assert.IsTrue(orderPayment1.Payments[0].Interactions[1].CheckNumber.Equals("12345"));
            Assert.AreEqual(orderPayment1.Payments[0].Interactions[1].Amount, getOrder.Total);
        }
Ejemplo n.º 30
0
 public void SetUp()
 {
     mockServiceScopeFactory = new MockServiceScopeFactory();
     paymentAction           = new PaymentAction(mockServiceScopeFactory.ServiceScopeFactory.Object);
 }
        public virtual IDictionary <string, string> GetParameters(PaymentRequest paymentRequest)
        {
            Payment payment = paymentRequest.Payment;

            OrderAddress billingAddress = payment.PurchaseOrder.GetBillingAddress();

            var orderAddress = billingAddress;
            var shipment     = payment.PurchaseOrder.Shipments.FirstOrDefault();

            if (shipment != null && shipment.ShipmentAddress != null)
            {
                orderAddress = shipment.ShipmentAddress;
            }


            string orderCurrency = paymentRequest.Payment.PurchaseOrder.BillingCurrency.ISOCode;
            string referenceId   = payment.ReferenceId;


            string callbackUrl = _callbackUrl.GetCallbackUrl(paymentRequest.PaymentMethod.DynamicProperty <string>().NotifyUrl, payment);
            string cancelUrl   = _absoluteUrlService.GetAbsoluteUrl(paymentRequest.PaymentMethod.DynamicProperty <string>().CancelReturn);

            IDictionary <string, string> values = new Dictionary <string, string>();

            // Set up call
            values.Add("USER", paymentRequest.PaymentMethod.DynamicProperty <string>().ApiUsername);
            values.Add("PWD", paymentRequest.PaymentMethod.DynamicProperty <string>().ApiPassword);
            values.Add("SIGNATURE", paymentRequest.PaymentMethod.DynamicProperty <string>().ApiSignature);
            values.Add("METHOD", "SetExpressCheckout");
            values.Add("VERSION", "98.0");

            //Add order values
            values.Add("RETURNURL", callbackUrl);
            values.Add("CANCELURL", cancelUrl);
            values.Add("NOSHIPPING", "1");
            values.Add("ALLOWNOTE", "0");
            var regionCode = GetRegionCode(paymentRequest);

            values.Add("LOCALECODE", regionCode);
            values.Add("SOLUTIONTYPE", "Sole");
            values.Add("EMAIL", billingAddress.EmailAddress);

            //Vendor code to identify Ucommerce
            values.Add("BUTTONSOURCE", "uCommerce_SP");

            values.Add("PAYMENTREQUEST_0_SHIPTONAME",
                       Uri.EscapeDataString(string.Format("{0} {1}", orderAddress.FirstName, orderAddress.LastName)));
            values.Add("PAYMENTREQUEST_0_SHIPTOSTREET", Uri.EscapeDataString(orderAddress.Line1));
            values.Add("PAYMENTREQUEST_0_SHIPTOSTREET2", Uri.EscapeDataString(orderAddress.Line2));
            values.Add("PAYMENTREQUEST_0_SHIPTOCITY", Uri.EscapeDataString(orderAddress.City));
            values.Add("PAYMENTREQUEST_0_SHIPTOSTATE", Uri.EscapeDataString(orderAddress.State));
            values.Add("PAYMENTREQUEST_0_SHIPTOZIP", Uri.EscapeDataString(orderAddress.PostalCode));
            values.Add("PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE", Uri.EscapeDataString(orderAddress.Country.TwoLetterISORegionName));
            values.Add("PAYMENTREQUEST_0_SHIPTOPHONENUM", Uri.EscapeDataString(orderAddress.PhoneNumber));

            string fullAmount = NumberWithTwoDecimalDigitsAfterPeriodAndNoThousandsSeperator(payment.Amount);

            values.Add("PAYMENTREQUEST_0_AMT", fullAmount);
            values.Add("PAYMENTREQUEST_0_CURRENCYCODE", orderCurrency);

            PaymentAction pa =
                EnumExtensions.ParsePaymentActionThrowExceptionOnFailure(payment.PaymentMethod.DynamicProperty <string>().PaymentAction);

            values.Add("PAYMENTREQUEST_0_PAYMENTACTION", pa.ToString());

            values.Add("PAYMENTREQUEST_0_INVNUM", referenceId);
            return(values);
        }
Ejemplo n.º 32
0
        public NameValueCollection DoExpressCheckoutPayment(decimal amount, CurrencyCodeType currencyCodeType, string payPalToken, string payPalPayerId, PaymentAction action)
        {
            var request = getQueryWithCredentials();

            request["METHOD"]  = "DoExpressCheckoutPayment";
            request["TOKEN"]   = payPalToken;
            request["PAYERID"] = payPalPayerId;
            request["PAYMENTREQUEST_0_AMT"]           = amount.ToString("0.00");
            request["PAYMENTREQUEST_0_CURRENCYCODE"]  = currencyCodeType.ToString();
            request["PAYMENTREQUEST_0_PAYMENTACTION"] = action.ToString();
            return(request);
        }