internal static HttpResponseMessage GetStatus(LatitudePayPurchaseStatusRequest request)
        {
            var existingPayment = (from p in _Payments where request.PaymentPlanToken == p.InitialResponse.Token select p).FirstOrDefault();

            if (existingPayment == null)
            {
                return(ToJsonHttpResponse(HttpStatusCode.NotFound, new { error = "Payment not found" }));
            }

            if (existingPayment.IsCancelled || existingPayment.CurrentPaymentStatus != LatitudePayConstants.StatusPending || DateTimeOffset.Now.Subtract(existingPayment.InitiallyReceivedAt) < TimeSpan.FromSeconds(5))
            {
                //Just return current status
            }
            else if (existingPayment.InitialRequest.TotalAmount.Amount.ToString("#0.00").EndsWith("88"))
            {
                existingPayment.CurrentPaymentStatus = LatitudePayConstants.StatusDeclined;
                existingPayment.StatusMessage        = "Declined: Credit denied";
            }
            else
            {
                existingPayment.CurrentPaymentStatus = LatitudePayConstants.StatusApproved;
                existingPayment.StatusMessage        = "Approved";
            }

            return(ToJsonHttpResponse(existingPayment.InitialResponseStatus, new LatitudePayPurchaseStatusResponse()
            {
                Message = existingPayment.StatusMessage, Status = existingPayment.CurrentPaymentStatus, Token = existingPayment.InitialResponse.Token
            }));
        }
        public async Task Refund()
        {
            using (var client = TestUtils.GetMockClient())
            {
                var request = new LatitudePayCreatePosPurchaseRequest()
                {
                    Reference      = "TBR-" + System.Guid.NewGuid().ToString(),
                    BillingAddress = new LatitudePayAddress()
                    {
                        AddressLine1 = "124 Fifth Avenue",
                        Suburb       = "Auckland",
                        CityTown     = "Auckland",
                        State        = "Auckland",
                        Postcode     = "1010",
                        CountryCode  = "NZ"
                    },
                    ShippingAddress = new LatitudePayAddress()
                    {
                        AddressLine1 = "124 Fifth Avenue",
                        Suburb       = "Auckland",
                        CityTown     = "Auckland",
                        State        = "Auckland",
                        Postcode     = "1010",
                        CountryCode  = "NZ"
                    },
                    Customer = new LatitudePayCustomer()
                    {
                        Address = new LatitudePayAddress()
                        {
                            AddressLine1 = "124 Fifth Avenue",
                            Suburb       = "Auckland",
                            CityTown     = "Auckland",
                            State        = "Auckland",
                            Postcode     = "1010",
                            CountryCode  = "NZ"
                        },
                        FirstName    = "John",
                        Surname      = "Doe",
                        MobileNumber = Environment.GetEnvironmentVariable("LatitudePay_TestMobileNumber")
                    },
                    Products = new List <LatitudePayProduct>()
                    {
                        new LatitudePayProduct()
                        {
                            Name        = "Tennis Ball Multipack",
                            Price       = new LatitudePayMoney(30, "NZD"),
                            Sku         = "abc123",
                            Quantity    = 1,
                            TaxIncluded = true
                        }
                    },
                    ShippingLines = new List <LatitiudePayShippingLine>()
                    {
                        new LatitiudePayShippingLine()
                        {
                            Carrier = "NZ Post",
                            Price   = new LatitudePayMoney(5.5M, "NZD")
                        }
                    },
                    TaxAmount   = new LatitudePayMoney(5.325M, "NZD"),
                    TotalAmount = new LatitudePayMoney(35.5M, "NZD"),
                    ReturnUrls  = new LatitudePayReturnUrls()
                    {
                        SuccessUrl  = new Uri("http://genoapay.com/success"),
                        FailUrl     = new Uri("http://genoapay.com/fail"),
                        CallbackUrl = new Uri("http://genoapay.com/fail-safe-callback")
                    }
                };

                var purchaseResponse = await client.CreatePosPurchaseAsync(request);

                Assert.IsNotNull(purchaseResponse);
                Assert.IsFalse(String.IsNullOrWhiteSpace(purchaseResponse.Token));
                Assert.IsNotNull(purchaseResponse.StatusUrl);

                //Wait until payment enters final status
                var statusRequest = new LatitudePayPurchaseStatusRequest()
                {
                    PaymentPlanToken = purchaseResponse.Token
                };
                var finalStatus = false;
                LatitudePayPurchaseStatusResponse paymentStatus;
                while (!finalStatus)
                {
                    await Task.Delay(5000).ConfigureAwait(false);

                    paymentStatus = await client.GetPurchaseStatusAsync(statusRequest).ConfigureAwait(false);

                    finalStatus = !String.Equals(paymentStatus.Status, LatitudePayConstants.StatusPending, StringComparison.OrdinalIgnoreCase);
                }

                var refundRequest = new LatitudePayCreateRefundRequest()
                {
                    PaymentPlanToken = purchaseResponse.Token, Amount = request.TotalAmount, Reason = "Test refund", Reference = System.Guid.NewGuid().ToString()
                };
                var refundResponse = await client.CreateRefundAsync(refundRequest);

                Assert.IsNotNull(refundResponse);
                Assert.IsFalse(String.IsNullOrEmpty(refundResponse.RefundId));
                Assert.IsFalse(String.IsNullOrEmpty(refundResponse.Reference));
            }
        }
Beispiel #3
0
        public async Task ThrowsUnauthorisedException_ForAuthorisationFailure()
        {
            var config = new LatitudePayClientConfiguration()
            {
                ApiKey      = "InvalidKey",
                ApiSecret   = "InvalidSecret",
                Environment = LatitudePayEnvironment.Uat
            };

            using (var client = new LatitudePayClient(config))
            {
                var request = new LatitudePayCreatePosPurchaseRequest()
                {
                    Reference      = System.Guid.NewGuid().ToString(),
                    BillingAddress = new LatitudePayAddress()
                    {
                        AddressLine1 = "124 Fifth Avenue",
                        Suburb       = "Auckland",
                        CityTown     = "Auckland",
                        State        = "Auckland",
                        Postcode     = "1010",
                        CountryCode  = "NZ"
                    },
                    ShippingAddress = new LatitudePayAddress()
                    {
                        AddressLine1 = "124 Fifth Avenue",
                        Suburb       = "Auckland",
                        CityTown     = "Auckland",
                        State        = "Auckland",
                        Postcode     = "1010",
                        CountryCode  = "NZ"
                    },
                    Customer = new LatitudePayCustomer()
                    {
                        Address = new LatitudePayAddress()
                        {
                            AddressLine1 = "124 Fifth Avenue",
                            Suburb       = "Auckland",
                            CityTown     = "Auckland",
                            State        = "Auckland",
                            Postcode     = "1010",
                            CountryCode  = "NZ"
                        },
                        FirstName    = "John",
                        Surname      = "Doe",
                        MobileNumber = Environment.GetEnvironmentVariable("LatitudePay_TestMobileNumber")
                    },
                    Products = new List <LatitudePayProduct>()
                    {
                        new LatitudePayProduct()
                        {
                            Name        = "Tennis Ball Multipack",
                            Price       = new LatitudePayMoney(30, "NZD"),
                            Sku         = "abc123",
                            Quantity    = 1,
                            TaxIncluded = true
                        }
                    },
                    ShippingLines = new List <LatitiudePayShippingLine>()
                    {
                        new LatitiudePayShippingLine()
                        {
                            Carrier = "NZ Post",
                            Price   = new LatitudePayMoney(5.5M, "NZD")
                        }
                    },
                    TaxAmount   = new LatitudePayMoney(5.325M, "NZD"),
                    TotalAmount = new LatitudePayMoney(35.5M, "NZD"),
                    ReturnUrls  = new LatitudePayReturnUrls()
                    {
                        SuccessUrl  = new Uri("http://genoapay.com/success"),
                        FailUrl     = new Uri("http://genoapay.com/fail"),
                        CallbackUrl = new Uri("http://genoapay.com/fail-safe-callback")
                    }
                };
                request.IdempotencyKey = request.Reference;

                var purchaseResponse = await client.CreatePosPurchaseAsync(request);

                Assert.IsNotNull(purchaseResponse);
                Assert.IsFalse(String.IsNullOrWhiteSpace(purchaseResponse.Token));
                Assert.IsNotNull(purchaseResponse.StatusUrl);

                //Wait until payment enters final status
                var statusRequest = new LatitudePayPurchaseStatusRequest()
                {
                    PaymentPlanToken = purchaseResponse.Token
                };
                var finalStatus = false;
                LatitudePayPurchaseStatusResponse paymentStatus = null;
                while (!finalStatus)
                {
                    await Task.Delay(5000).ConfigureAwait(false);

                    paymentStatus = await client.GetPurchaseStatusAsync(statusRequest).ConfigureAwait(false);

                    finalStatus = !String.Equals(paymentStatus.Status, LatitudePayConstants.StatusPending, StringComparison.OrdinalIgnoreCase);
                }

                Assert.AreEqual(LatitudePayConstants.StatusApproved, paymentStatus.Status);
                Assert.IsFalse(String.IsNullOrEmpty(paymentStatus.Token));
                Assert.IsFalse(String.IsNullOrEmpty(paymentStatus.Message));
            }
        }
Beispiel #4
0
        public async Task Cancel_Genoapay()
        {
            using (var client = TestUtils.GetGenoapaySandboxClient())
            {
                var request = new LatitudePayCreatePosPurchaseRequest()
                {
                    Reference      = "TBC-" + System.Guid.NewGuid().ToString(),
                    BillingAddress = new LatitudePayAddress()
                    {
                        AddressLine1 = "124 Fifth Avenue",
                        Suburb       = "Auckland",
                        CityTown     = "Auckland",
                        State        = "Auckland",
                        Postcode     = "1010",
                        CountryCode  = "NZ"
                    },
                    ShippingAddress = new LatitudePayAddress()
                    {
                        AddressLine1 = "124 Fifth Avenue",
                        Suburb       = "Auckland",
                        CityTown     = "Auckland",
                        State        = "Auckland",
                        Postcode     = "1010",
                        CountryCode  = "NZ"
                    },
                    Customer = new LatitudePayCustomer()
                    {
                        Address = new LatitudePayAddress()
                        {
                            AddressLine1 = "124 Fifth Avenue",
                            Suburb       = "Auckland",
                            CityTown     = "Auckland",
                            State        = "Auckland",
                            Postcode     = "1010",
                            CountryCode  = "NZ"
                        },
                        FirstName    = "John",
                        Surname      = "Doe",
                        MobileNumber = "025555555"                         //UAT environment allows us to use any mobile number that starts 02x-xxx-xxx, and this number shouldn't actually be in use so shouldn't bother anyone from automated tests
                    },
                    Products = new List <LatitudePayProduct>()
                    {
                        new LatitudePayProduct()
                        {
                            Name        = "Tennis Ball Multipack",
                            Price       = new LatitudePayMoney(30, "NZD"),
                            Sku         = "abc123",
                            Quantity    = 1,
                            TaxIncluded = true
                        }
                    },
                    ShippingLines = new List <LatitiudePayShippingLine>()
                    {
                        new LatitiudePayShippingLine()
                        {
                            Carrier = "NZ Post",
                            Price   = new LatitudePayMoney(5.5M, "NZD")
                        }
                    },
                    TaxAmount   = new LatitudePayMoney(5.325M, "NZD"),
                    TotalAmount = new LatitudePayMoney(35.5M, "NZD"),
                    ReturnUrls  = new LatitudePayReturnUrls()
                    {
                        SuccessUrl  = new Uri("http://genoapay.com/success"),
                        FailUrl     = new Uri("http://genoapay.com/fail"),
                        CallbackUrl = new Uri("http://genoapay.com/fail-safe-callback")
                    }
                };

                var purchaseResponse = await client.CreatePosPurchaseAsync(request);

                Assert.IsNotNull(purchaseResponse);
                Assert.IsFalse(String.IsNullOrWhiteSpace(purchaseResponse.Token));
                Assert.IsNotNull(purchaseResponse.StatusUrl);

                //Wait until payment enters final status
                var cancelRequest = new LatitudePayCancelPurchaseRequest()
                {
                    PaymentPlanToken = purchaseResponse.Token
                };

                await Task.Delay(5000).ConfigureAwait(false);

                var cancelResponse = await client.CancelPurchaseAsync(cancelRequest).ConfigureAwait(false);

                Assert.IsNotNull(cancelResponse);
                Assert.IsFalse(String.IsNullOrWhiteSpace(cancelResponse.Token));

                var statusRequest = new LatitudePayPurchaseStatusRequest()
                {
                    PaymentPlanToken = purchaseResponse.Token
                };
                var paymentStatus = await client.GetPurchaseStatusAsync(statusRequest).ConfigureAwait(false);

                Assert.IsNotNull(paymentStatus);
                Assert.AreEqual(LatitudePayConstants.StatusDeclined, paymentStatus.Status);
            }
        }