Exemple #1
0
        public void TestCreatePaymentRejected()
        {
            // an exception is thrown after logging the response

            TestLogger logger = new TestLogger();

            using (MockServer host = new MockServer(Port, "/v2/1/payments", (request, response, arg3) =>
            {
                AssignResponse((HttpStatusCode)402, new Dictionary <string, string>(), response);

                return(createPaymentFailureRejectedJson);
            }))
                using (IClient client = CreateClient())
                {
                    client.EnableLogging(logger);

                    AmountOfMoney amountOfMoney = new AmountOfMoney();
                    amountOfMoney.CurrencyCode = "EUR";
                    amountOfMoney.Amount       = 2345L;

                    Address billingAddress = new Address();
                    billingAddress.CountryCode = "BE";

                    Customer customer = new Customer();
                    customer.BillingAddress = billingAddress;

                    Order order = new Order();
                    order.AmountOfMoney = amountOfMoney;
                    order.Customer      = customer;

                    Card card = new Card();
                    card.Cvv        = "123";
                    card.CardNumber = "1234567890123452";
                    card.ExpiryDate = "1230";

                    CardPaymentMethodSpecificInput paymentMethodSpecificInput = new CardPaymentMethodSpecificInput();
                    paymentMethodSpecificInput.PaymentProductId = 1;
                    paymentMethodSpecificInput.Card             = card;

                    CreatePaymentRequest request = new CreatePaymentRequest();
                    request.Order = order;
                    request.CardPaymentMethodSpecificInput = paymentMethodSpecificInput;

                    Assert.CatchAsync(typeof(DeclinedPaymentException), async() => await client.WithNewMerchant("1").Payments.CreatePayment(request)
                                      .ConfigureAwait(false));
                }
            Assert.That(logger.Entries, Has.Count.EqualTo(2));

            TestLoggerEntry requestEntry = logger.Entries.First();

            Assert.That(requestEntry.Message, Is.Not.Null);
            Assert.That(requestEntry.Thrown, Is.Null);

            TestLoggerEntry responseEntry = logger.Entries.ElementAt(1);

            Assert.That(responseEntry.Message, Is.Not.Null);
            Assert.That(responseEntry.Thrown, Is.Null);

            AssertRequestAndResponse(requestEntry.Message, responseEntry.Message, createPaymentFailureRejectedRequest, createPaymentFailureRejectedResponse);
        }
        public async Task Test()
        {
            CreatePaymentRequest body = new CreatePaymentRequest();

            Order order = new Order();

            AmountOfMoney amountOfMoney = new AmountOfMoney();

            amountOfMoney.CurrencyCode = ("EUR");
            amountOfMoney.Amount       = (100L);
            order.AmountOfMoney        = (amountOfMoney);

            Customer customer = new Customer();

            customer.Locale = ("en");

            Address billingAddress = new Address();

            billingAddress.CountryCode = ("NL");
            customer.BillingAddress    = (billingAddress);

            order.Customer = (customer);
            body.Order     = (order);

            RedirectionData redirectionData = new RedirectionData();

            redirectionData.ReturnUrl = ("http://example.com/");

            RedirectPaymentMethodSpecificInput paymentMethodSpecificInput = new RedirectPaymentMethodSpecificInput();

            paymentMethodSpecificInput.RedirectionData  = redirectionData;
            paymentMethodSpecificInput.PaymentProductId = (809);

            RedirectPaymentProduct809SpecificInput paymentProductSpecificInput = new RedirectPaymentProduct809SpecificInput();

            paymentProductSpecificInput.IssuerId = ("INGBNL2A");
            paymentMethodSpecificInput.PaymentProduct809SpecificInput = (paymentProductSpecificInput);

            body.RedirectPaymentMethodSpecificInput = (paymentMethodSpecificInput);

            string      idempotenceKey = Guid.NewGuid().ToString();
            CallContext context        = new CallContext().WithIdempotenceKey(idempotenceKey);

            using (Client client = GetClient())
            {
                CreatePaymentResponse response = await client.Merchant(GetMerchantId()).Payments().Create(body, context);

                string paymentId = response.Payment.Id;

                Assert.AreEqual(idempotenceKey, context.IdempotenceKey);
                Assert.Null(context.IdempotenceRequestTimestamp);

                response = await client.Merchant(GetMerchantId()).Payments().Create(body, context);

                Assert.AreEqual(paymentId, response.Payment.Id);

                Assert.AreEqual(idempotenceKey, context.IdempotenceKey);
                Assert.NotNull(context.IdempotenceRequestTimestamp);
            }
        }
Exemple #3
0
        public async void Example()
        {
#pragma warning disable 0168
            using (Client client = GetClient())
            {
                BankAccountBban bankAccountBban = new BankAccountBban();
                bankAccountBban.AccountNumber = "0532013000";
                bankAccountBban.BankCode      = "37040044";
                bankAccountBban.CountryCode   = "DE";

                AmountOfMoney amountOfMoney = new AmountOfMoney();
                amountOfMoney.Amount       = 100L;
                amountOfMoney.CurrencyCode = "EUR";

                Address billingAddress = new Address();
                billingAddress.CountryCode = "US";

                CustomerRiskAssessment customer = new CustomerRiskAssessment();
                customer.BillingAddress = billingAddress;
                customer.Locale         = "en_US";

                OrderRiskAssessment order = new OrderRiskAssessment();
                order.AmountOfMoney = amountOfMoney;
                order.Customer      = customer;

                RiskAssessmentBankAccount body = new RiskAssessmentBankAccount();
                body.BankAccountBban = bankAccountBban;
                body.Order           = order;

                RiskAssessmentResponse response = await client.Merchant("merchantId").Riskassessments().Bankaccounts(body);
            }
#pragma warning restore 0168
        }
Exemple #4
0
        public async void Example()
        {
#pragma warning disable 0168
            using (Client client = GetClient())
            {
                HostedCheckoutSpecificInput hostedCheckoutSpecificInput = new HostedCheckoutSpecificInput();
                hostedCheckoutSpecificInput.Locale  = "en_GB";
                hostedCheckoutSpecificInput.Variant = "testVariant";

                AmountOfMoney amountOfMoney = new AmountOfMoney();
                amountOfMoney.Amount       = 2345L;
                amountOfMoney.CurrencyCode = "USD";

                Address billingAddress = new Address();
                billingAddress.CountryCode = "US";

                Customer customer = new Customer();
                customer.BillingAddress = billingAddress;

                Order order = new Order();
                order.AmountOfMoney = amountOfMoney;
                order.Customer      = customer;

                CreateHostedCheckoutRequest body = new CreateHostedCheckoutRequest();
                body.HostedCheckoutSpecificInput = hostedCheckoutSpecificInput;
                body.Order = order;

                CreateHostedCheckoutResponse response = await client.Merchant("merchantId").Hostedcheckouts().Create(body);
            }
#pragma warning restore 0168
        }
        public async void Example()
        {
#pragma warning disable 0168
            using (Client client = GetClient())
            {
                AmountOfMoney amountOfMoney = new AmountOfMoney();
                amountOfMoney.Amount       = 500L;
                amountOfMoney.CurrencyCode = "EUR";

                RefundReferences refundReferences = new RefundReferences();
                refundReferences.MerchantReference = "AcmeOrder0001";

                RefundRequest body = new RefundRequest();
                body.AmountOfMoney    = amountOfMoney;
                body.RefundReferences = refundReferences;

                try
                {
                    RefundResponse response = await client.Merchant("merchantId").Captures().Refund("captureId", body);
                }
                catch (DeclinedRefundException e)
                {
                    HandleDeclinedRefund(e.RefundResult);
                }
                catch (ApiException e)
                {
                    HandleApiErrors(e.Errors);
                }
            }
#pragma warning restore 0168
        }
Exemple #6
0
        public async void Example()
        {
#pragma warning disable 0168
            using (Client client = GetClient())
            {
                AmountOfMoney amountOfMoney = new AmountOfMoney();
                amountOfMoney.Amount       = 1L;
                amountOfMoney.CurrencyCode = "EUR";

                BankAccountIban bankAccountIban = new BankAccountIban();
                bankAccountIban.Iban = "NL53INGB0000000036";

                BankRefundMethodSpecificInput bankRefundMethodSpecificInput = new BankRefundMethodSpecificInput();
                bankRefundMethodSpecificInput.BankAccountIban = bankAccountIban;

                PersonalName name = new PersonalName();
                name.Surname = "Coyote";

                AddressPersonal address = new AddressPersonal();
                address.CountryCode = "US";
                address.Name        = name;

                ContactDetailsBase contactDetails = new ContactDetailsBase();
                contactDetails.EmailAddress     = "*****@*****.**";
                contactDetails.EmailMessageType = "html";

                RefundCustomer customer = new RefundCustomer();
                customer.Address        = address;
                customer.ContactDetails = contactDetails;

                RefundReferences refundReferences = new RefundReferences();
                refundReferences.MerchantReference = "AcmeOrder0001";

                RefundRequest body = new RefundRequest();
                body.AmountOfMoney = amountOfMoney;
                body.BankRefundMethodSpecificInput = bankRefundMethodSpecificInput;
                body.Customer         = customer;
                body.RefundDate       = "20140306";
                body.RefundReferences = refundReferences;

                try
                {
                    RefundResponse response = await client.Merchant("merchantId").Payments().Refund("paymentId", body);
                }
                catch (DeclinedRefundException e)
                {
                    HandleDeclinedRefund(e.RefundResult);
                }
                catch (ApiException e)
                {
                    HandleApiErrors(e.Errors);
                }
            }
#pragma warning restore 0168
        }
Exemple #7
0
        public async void Example()
        {
#pragma warning disable 0168
            using (Client client = GetClient())
            {
                AmountOfMoney amountOfMoney = new AmountOfMoney();
                amountOfMoney.Amount       = 1234L;
                amountOfMoney.CurrencyCode = "USD";

                CreateDisputeRequest body = new CreateDisputeRequest();
                body.AmountOfMoney  = amountOfMoney;
                body.ContactPerson  = "Wile Coyote";
                body.EmailAddress   = "*****@*****.**";
                body.ReplyTo        = "*****@*****.**";
                body.RequestMessage = "This is the message from the merchant to GlobalCollect. It is a a freeform text field.";

                DisputeResponse response = await client.Merchant("merchantId").Payments().Dispute("paymentId", body);
            }
#pragma warning restore 0168
        }
Exemple #8
0
        CreatePaymentRequest CreateRequest()
        {
            CreatePaymentRequest body = new CreatePaymentRequest();

            Order order = new Order();

            AmountOfMoney amountOfMoney = new AmountOfMoney();

            amountOfMoney.Amount       = 2345L;
            amountOfMoney.CurrencyCode = "CAD";
            order.AmountOfMoney        = amountOfMoney;

            Customer customer = new Customer();

            Address billingAddress = new Address();

            billingAddress.CountryCode = "CA";
            customer.BillingAddress    = (billingAddress);

            order.Customer = customer;

            CardPaymentMethodSpecificInput cardPaymentMethodSpecificInput = new CardPaymentMethodSpecificInput();

            cardPaymentMethodSpecificInput.PaymentProductId = 1;

            Card card = new Card();

            card.Cvv        = "123";
            card.CardNumber = "4567350000427977";
            card.ExpiryDate = "1220";
            cardPaymentMethodSpecificInput.Card = card;

            body.CardPaymentMethodSpecificInput = cardPaymentMethodSpecificInput;

            return(body);
        }
Exemple #9
0
        public async Task Test()
        {
            RiskAssessmentBankAccount body = new RiskAssessmentBankAccount();

            BankAccountBban bankAccountBban = new BankAccountBban();

            bankAccountBban.CountryCode   = ("DE");
            bankAccountBban.AccountNumber = ("0532013000");
            bankAccountBban.BankCode      = ("37040044");
            body.BankAccountBban          = (bankAccountBban);

            OrderRiskAssessment order = new OrderRiskAssessment();

            AmountOfMoney amountOfMoney = new AmountOfMoney();

            amountOfMoney.Amount       = (100L);
            amountOfMoney.CurrencyCode = ("EUR");
            order.AmountOfMoney        = (amountOfMoney);

            CustomerRiskAssessment customer = new CustomerRiskAssessment();

            customer.Locale = ("en_GB");
            order.Customer  = (customer);

            body.Order = (order);

            using (Client client = GetClient())
            {
                RiskAssessmentResponse riskAssessmentResponse = await client
                                                                .Merchant(GetMerchantId())
                                                                .Riskassessments()
                                                                .Bankaccounts(body);

                Assert.That(riskAssessmentResponse.Results, Is.Not.Empty);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="customer"></param>
        /// <param name="customerPayment"></param>
        /// <param name="returnUrl">The URL that the user will be redirected to after the payment process.</param>
        /// <returns></returns>
        public async Task <string> CreateHostedCheckoutAsync(Entities.Customer customer, Entities.CustomerPayment customerPayment, string returnUrl)
        {
            var result = string.Empty;

            using (Client client = GetClient())
            {
                var ingenicoSettings      = _configuration.GetSection("Ingenico");
                var merchantId            = ingenicoSettings.GetValue <string>("MerchantID");
                var hostedCheckoutVariant = ingenicoSettings.GetValue <string>("HostedCheckoutVariant");
                var currency = string.IsNullOrEmpty(customerPayment.Currency) ? ingenicoSettings.GetValue <string>("DefaultCurrency") : customerPayment.Currency;
                var locale   = string.IsNullOrEmpty(customer.Locale) ? ingenicoSettings.GetValue <string>("DefaultLocale") : customer.Locale;

                var hostedCheckoutSpecificInput = new HostedCheckoutSpecificInput
                {
                    IsRecurring           = false,
                    Locale                = locale,
                    Variant               = hostedCheckoutVariant,
                    ReturnCancelState     = true,
                    PaymentProductFilters = new PaymentProductFiltersHostedCheckout()
                    {
                        // Only allow certain payment methods
                        RestrictTo = new PaymentProductFilter
                        {
                            Products = PaymentProductIncludeIds
                        }
                    }
                };

                var amountOfMoney = new AmountOfMoney
                {
                    Amount       = ConvertToIngenicoAmount(customerPayment.Total == 0 ? 0.01m : customerPayment.Total), // Amount cannot be zero. Amount has to be at least 1 cent.
                    CurrencyCode = currency
                };

                var order = new Order
                {
                    Customer      = CreateIngenicoCustomer(customer),
                    AmountOfMoney = amountOfMoney,
                    References    = new OrderReferences
                    {
                        // Update Order with CustomerPayment Id as reference
                        MerchantReference = customerPayment.MerchantReference.ToString()
                    }
                };

                // Create Hosted Checkout for recurring monthly direct debit via credit card or Sepa direct debit payment methods for subscription purchase

                var cardPaymentMethodSpecificInput = new CardPaymentMethodSpecificInputBase
                {
                    Tokenize  = true,
                    Recurring = new CardRecurrenceDetails
                    {
                        RecurringPaymentSequenceIndicator = "first"
                    },
                    AuthorizationMode = "SALE",
                    RequiresApproval  = false
                };

                var sepaDirectDebitPaymentMethodSpecificInput = new SepaDirectDebitPaymentMethodSpecificInputBase()
                {
                    PaymentProduct771SpecificInput = new SepaDirectDebitPaymentProduct771SpecificInputBase()
                    {
                        Mandate = new CreateMandateBase()
                        {
                            CustomerReference = order.Customer.MerchantCustomerId,
                            RecurrenceType    = "RECURRING",
                            SignatureType     = "SMS"
                        },
                    }
                };

                var body = new CreateHostedCheckoutRequest
                {
                    HostedCheckoutSpecificInput = hostedCheckoutSpecificInput,
                    Order = order,
                    CardPaymentMethodSpecificInput            = cardPaymentMethodSpecificInput,
                    SepaDirectDebitPaymentMethodSpecificInput = sepaDirectDebitPaymentMethodSpecificInput
                };

                try
                {
                    // Initial call to Ingenico API to create hosted checkout.
                    CreateHostedCheckoutResponse createHostedCheckoutResponse = await client.Merchant(merchantId).Hostedcheckouts().Create(body);

                    if (createHostedCheckoutResponse.MerchantReference == customerPayment.MerchantReference.ToString())
                    {
                        // Do initial call to Ingenico API to retreive status of payment
                        GetHostedCheckoutResponse getHostedCheckoutResponse = await client.Merchant(merchantId).Hostedcheckouts().Get(createHostedCheckoutResponse.HostedCheckoutId);

                        // Update CustomerPayment record
                        customerPayment.Status = getHostedCheckoutResponse.Status;
                        //_customerPaymentRepository.Update(customerPayment);
                    }

                    // Build up redirect URL
                    var subdomain = ingenicoSettings.GetValue <string>("Subdomain");
                    result = $"{subdomain}{createHostedCheckoutResponse.PartialRedirectUrl}";
                }
                catch (Exception ex)
                {
                    //Logger.Error("Exception at : PaymentManager.CreateHostedCheckout\n", ex);

                    // Delete Customer Payment records, since initial payment failed
                    //_customerPaymentRepository.Delete(customerPayment.Id);
                }
            }

            return(result);
        }
        public async void Example()
        {
#pragma warning disable 0168
            using (Client client = GetClient())
            {
                AmountOfMoney amountOfMoney = new AmountOfMoney();
                amountOfMoney.Amount       = 2345L;
                amountOfMoney.CurrencyCode = "EUR";

                BankAccountIban bankAccountIban = new BankAccountIban();
                bankAccountIban.AccountHolderName = "Wile E. Coyote";
                bankAccountIban.Iban = "IT60X0542811101000000123456";

                Address address = new Address();
                address.City        = "Burbank";
                address.CountryCode = "US";
                address.HouseNumber = "411";
                address.State       = "California";
                address.Street      = "N Hollywood Way";
                address.Zip         = "91505";

                CompanyInformation companyInformation = new CompanyInformation();
                companyInformation.Name = "Acme Labs";

                ContactDetailsBase contactDetails = new ContactDetailsBase();
                contactDetails.EmailAddress = "*****@*****.**";

                PersonalName name = new PersonalName();
                name.FirstName     = "Wile";
                name.Surname       = "Coyote";
                name.SurnamePrefix = "E.";
                name.Title         = "Mr.";

                PayoutCustomer customer = new PayoutCustomer();
                customer.Address            = address;
                customer.CompanyInformation = companyInformation;
                customer.ContactDetails     = contactDetails;
                customer.Name = name;

                BankTransferPayoutMethodSpecificInput bankTransferPayoutMethodSpecificInput = new BankTransferPayoutMethodSpecificInput();
                bankTransferPayoutMethodSpecificInput.BankAccountIban = bankAccountIban;
                bankTransferPayoutMethodSpecificInput.Customer        = customer;
                bankTransferPayoutMethodSpecificInput.PayoutDate      = "20150102";
                bankTransferPayoutMethodSpecificInput.PayoutText      = "Payout Acme";
                bankTransferPayoutMethodSpecificInput.SwiftCode       = "swift";

                PayoutReferences references = new PayoutReferences();
                references.MerchantReference = "AcmeOrder001";

                CreatePayoutRequest body = new CreatePayoutRequest();
                body.AmountOfMoney = amountOfMoney;
                body.BankTransferPayoutMethodSpecificInput = bankTransferPayoutMethodSpecificInput;
                body.References = references;

                try
                {
                    PayoutResponse response = await client.Merchant("merchantId").Payouts().Create(body);
                }
                catch (DeclinedPayoutException e)
                {
                    HandleDeclinedPayout(e.PayoutResult);
                }
                catch (ApiException e)
                {
                    HandleApiErrors(e.Errors);
                }
            }
#pragma warning restore 0168
        }
Exemple #12
0
        public async void Example()
        {
#pragma warning disable 0168
            using (Client client = GetClient())
            {
                Card card = new Card();
                card.CardNumber     = "4567350000427977";
                card.CardholderName = "Wile E. Coyote";
                card.Cvv            = "123";
                card.ExpiryDate     = "1220";

                CardPaymentMethodSpecificInput cardPaymentMethodSpecificInput = new CardPaymentMethodSpecificInput();
                cardPaymentMethodSpecificInput.Card               = card;
                cardPaymentMethodSpecificInput.PaymentProductId   = 1;
                cardPaymentMethodSpecificInput.SkipAuthentication = false;

                AmountOfMoney amountOfMoney = new AmountOfMoney();
                amountOfMoney.Amount       = 2980L;
                amountOfMoney.CurrencyCode = "EUR";

                Address billingAddress = new Address();
                billingAddress.AdditionalInfo = "b";
                billingAddress.City           = "Monument Valley";
                billingAddress.CountryCode    = "US";
                billingAddress.HouseNumber    = "13";
                billingAddress.State          = "Utah";
                billingAddress.Street         = "Desertroad";
                billingAddress.Zip            = "84536";

                CompanyInformation companyInformation = new CompanyInformation();
                companyInformation.Name = "Acme Labs";

                ContactDetails contactDetails = new ContactDetails();
                contactDetails.EmailAddress     = "*****@*****.**";
                contactDetails.EmailMessageType = "html";
                contactDetails.FaxNumber        = "+1234567891";
                contactDetails.PhoneNumber      = "+1234567890";

                PersonalName name = new PersonalName();
                name.FirstName     = "Wile";
                name.Surname       = "Coyote";
                name.SurnamePrefix = "E.";
                name.Title         = "Mr.";

                PersonalInformation personalInformation = new PersonalInformation();
                personalInformation.DateOfBirth = "19490917";
                personalInformation.Gender      = "male";
                personalInformation.Name        = name;

                PersonalName shippingName = new PersonalName();
                shippingName.FirstName = "Road";
                shippingName.Surname   = "Runner";
                shippingName.Title     = "Miss";

                AddressPersonal shippingAddress = new AddressPersonal();
                shippingAddress.AdditionalInfo = "Suite II";
                shippingAddress.City           = "Monument Valley";
                shippingAddress.CountryCode    = "US";
                shippingAddress.HouseNumber    = "1";
                shippingAddress.Name           = shippingName;
                shippingAddress.State          = "Utah";
                shippingAddress.Street         = "Desertroad";
                shippingAddress.Zip            = "84536";

                Customer customer = new Customer();
                customer.BillingAddress      = billingAddress;
                customer.CompanyInformation  = companyInformation;
                customer.ContactDetails      = contactDetails;
                customer.Locale              = "en_US";
                customer.MerchantCustomerId  = "1234";
                customer.PersonalInformation = personalInformation;
                customer.ShippingAddress     = shippingAddress;
                customer.VatNumber           = "1234AB5678CD";

                OrderInvoiceData invoiceData = new OrderInvoiceData();
                invoiceData.InvoiceDate   = "20140306191500";
                invoiceData.InvoiceNumber = "000000123";

                OrderReferences references = new OrderReferences();
                references.Descriptor        = "Fast and Furry-ous";
                references.InvoiceData       = invoiceData;
                references.MerchantOrderId   = 123456L;
                references.MerchantReference = "AcmeOrder0001";

                IList <LineItem> items = new List <LineItem>();

                AmountOfMoney item1AmountOfMoney = new AmountOfMoney();
                item1AmountOfMoney.Amount       = 2500L;
                item1AmountOfMoney.CurrencyCode = "EUR";

                LineItemInvoiceData item1InvoiceData = new LineItemInvoiceData();
                item1InvoiceData.Description  = "ACME Super Outfit";
                item1InvoiceData.NrOfItems    = "1";
                item1InvoiceData.PricePerItem = 2500L;

                LineItem item1 = new LineItem();
                item1.AmountOfMoney = item1AmountOfMoney;
                item1.InvoiceData   = item1InvoiceData;

                items.Add(item1);

                AmountOfMoney item2AmountOfMoney = new AmountOfMoney();
                item2AmountOfMoney.Amount       = 480L;
                item2AmountOfMoney.CurrencyCode = "EUR";

                LineItemInvoiceData item2InvoiceData = new LineItemInvoiceData();
                item2InvoiceData.Description  = "Aspirin";
                item2InvoiceData.NrOfItems    = "12";
                item2InvoiceData.PricePerItem = 40L;

                LineItem item2 = new LineItem();
                item2.AmountOfMoney = item2AmountOfMoney;
                item2.InvoiceData   = item2InvoiceData;

                items.Add(item2);

                ShoppingCart shoppingCart = new ShoppingCart();
                shoppingCart.Items = items;

                Order order = new Order();
                order.AmountOfMoney = amountOfMoney;
                order.Customer      = customer;
                order.References    = references;
                order.ShoppingCart  = shoppingCart;

                CreatePaymentRequest body = new CreatePaymentRequest();
                body.CardPaymentMethodSpecificInput = cardPaymentMethodSpecificInput;
                body.Order = order;

                try
                {
                    CreatePaymentResponse response = await client.Merchant("merchantId").Payments().Create(body);
                }
                catch (DeclinedPaymentException e)
                {
                    HandleDeclinedPayment(e.CreatePaymentResult);
                }
                catch (ApiException e)
                {
                    HandleApiErrors(e.Errors);
                }
            }
#pragma warning restore 0168
        }
Exemple #13
0
        public async void Example()
        {
#pragma warning disable 0168
            using (Client client = GetClient())
            {
                Card card = new Card();
                card.CardNumber = "4567350000427977";
                card.Cvv        = "123";
                card.ExpiryDate = "0820";

                IList <AirlineFlightLeg> flightLegs = new List <AirlineFlightLeg>();

                AirlineFlightLeg flightLeg1 = new AirlineFlightLeg();
                flightLeg1.AirlineClass   = "1";
                flightLeg1.ArrivalAirport = "AMS";
                flightLeg1.CarrierCode    = "KL";
                flightLeg1.Date           = "20150102";
                flightLeg1.DepartureTime  = "17:59";
                flightLeg1.Fare           = "fare";
                flightLeg1.FareBasis      = "INTERNET";
                flightLeg1.FlightNumber   = "791";
                flightLeg1.Number         = 1;
                flightLeg1.OriginAirport  = "BCN";
                flightLeg1.StopoverCode   = "non-permitted";

                flightLegs.Add(flightLeg1);

                AirlineFlightLeg flightLeg2 = new AirlineFlightLeg();
                flightLeg2.AirlineClass   = "1";
                flightLeg2.ArrivalAirport = "BCN";
                flightLeg2.CarrierCode    = "KL";
                flightLeg2.Date           = "20150102";
                flightLeg2.DepartureTime  = "23:59";
                flightLeg2.Fare           = "fare";
                flightLeg2.FareBasis      = "INTERNET";
                flightLeg2.FlightNumber   = "792";
                flightLeg2.Number         = 2;
                flightLeg2.OriginAirport  = "AMS";
                flightLeg2.StopoverCode   = "non-permitted";

                flightLegs.Add(flightLeg2);

                AirlineData airlineData = new AirlineData();
                airlineData.AgentNumericCode   = "123321";
                airlineData.Code               = "123";
                airlineData.FlightDate         = "20150102";
                airlineData.FlightLegs         = flightLegs;
                airlineData.InvoiceNumber      = "123456";
                airlineData.IsETicket          = true;
                airlineData.IsRestrictedTicket = true;
                airlineData.IsThirdParty       = true;
                airlineData.IssueDate          = "20150101";
                airlineData.MerchantCustomerId = "14";
                airlineData.Name               = "Air France KLM";
                airlineData.PassengerName      = "WECOYOTE";
                airlineData.PlaceOfIssue       = "Utah";
                airlineData.Pnr                  = "4JTGKT";
                airlineData.PointOfSale          = "IATA point of sale name";
                airlineData.PosCityCode          = "AMS";
                airlineData.TicketDeliveryMethod = "e-ticket";
                airlineData.TicketNumber         = "KLM20050000";

                AdditionalOrderInputAirlineData additionalInput = new AdditionalOrderInputAirlineData();
                additionalInput.AirlineData = airlineData;

                AmountOfMoney amountOfMoney = new AmountOfMoney();
                amountOfMoney.Amount       = 100L;
                amountOfMoney.CurrencyCode = "EUR";

                Address billingAddress = new Address();
                billingAddress.CountryCode = "US";

                CustomerRiskAssessment customer = new CustomerRiskAssessment();
                customer.AccountType    = "existing";
                customer.BillingAddress = billingAddress;
                customer.Locale         = "en_US";

                OrderRiskAssessment order = new OrderRiskAssessment();
                order.AdditionalInput = additionalInput;
                order.AmountOfMoney   = amountOfMoney;
                order.Customer        = customer;

                RiskAssessmentCard body = new RiskAssessmentCard();
                body.Card  = card;
                body.Order = order;

                RiskAssessmentResponse response = await client.Merchant("merchantId").Riskassessments().Cards(body);
            }
#pragma warning restore 0168
        }
        public async void Example()
        {
#pragma warning disable 0168
            using (Client client = GetClient())
            {
                Card card = new Card();
                card.CardNumber     = "4567350000427977";
                card.CardholderName = "Wile E. Coyote";
                card.Cvv            = "123";
                card.ExpiryDate     = "1220";

                RedirectionData redirectionData = new RedirectionData();
                redirectionData.ReturnUrl = "https://hostname.myownwebsite.url";

                ThreeDSecure threeDSecure = new ThreeDSecure();
                threeDSecure.AuthenticationFlow  = "browser";
                threeDSecure.ChallengeCanvasSize = "600x400";
                threeDSecure.ChallengeIndicator  = "challenge-requested";
                threeDSecure.ExemptionRequest    = "none";
                threeDSecure.RedirectionData     = redirectionData;
                threeDSecure.SkipAuthentication  = false;

                CardPaymentMethodSpecificInput cardPaymentMethodSpecificInput = new CardPaymentMethodSpecificInput();
                cardPaymentMethodSpecificInput.Card        = card;
                cardPaymentMethodSpecificInput.IsRecurring = false;
                cardPaymentMethodSpecificInput.MerchantInitiatedReasonIndicator = "delayedCharges";
                cardPaymentMethodSpecificInput.PaymentProductId   = 1;
                cardPaymentMethodSpecificInput.ThreeDSecure       = threeDSecure;
                cardPaymentMethodSpecificInput.TransactionChannel = "ECOMMERCE";

                AmountOfMoney amountOfMoney = new AmountOfMoney();
                amountOfMoney.Amount       = 2980L;
                amountOfMoney.CurrencyCode = "EUR";

                Address billingAddress = new Address();
                billingAddress.AdditionalInfo = "b";
                billingAddress.City           = "Monument Valley";
                billingAddress.CountryCode    = "US";
                billingAddress.HouseNumber    = "13";
                billingAddress.State          = "Utah";
                billingAddress.Street         = "Desertroad";
                billingAddress.Zip            = "84536";

                CompanyInformation companyInformation = new CompanyInformation();
                companyInformation.Name      = "Acme Labs";
                companyInformation.VatNumber = "1234AB5678CD";

                ContactDetails contactDetails = new ContactDetails();
                contactDetails.EmailAddress = "*****@*****.**";
                contactDetails.FaxNumber    = "+1234567891";
                contactDetails.PhoneNumber  = "+1234567890";

                BrowserData browserData = new BrowserData();
                browserData.ColorDepth   = 24;
                browserData.JavaEnabled  = false;
                browserData.ScreenHeight = "1200";
                browserData.ScreenWidth  = "1920";

                CustomerDevice device = new CustomerDevice();
                device.AcceptHeader             = "texthtml,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                device.BrowserData              = browserData;
                device.IpAddress                = "123.123.123.123";
                device.Locale                   = "en-US";
                device.TimezoneOffsetUtcMinutes = "420";
                device.UserAgent                = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15";

                PersonalName name = new PersonalName();
                name.FirstName     = "Wile";
                name.Surname       = "Coyote";
                name.SurnamePrefix = "E.";
                name.Title         = "Mr.";

                PersonalInformation personalInformation = new PersonalInformation();
                personalInformation.DateOfBirth = "19490917";
                personalInformation.Gender      = "male";
                personalInformation.Name        = name;

                Customer customer = new Customer();
                customer.AccountType         = "none";
                customer.BillingAddress      = billingAddress;
                customer.CompanyInformation  = companyInformation;
                customer.ContactDetails      = contactDetails;
                customer.Device              = device;
                customer.Locale              = "en_US";
                customer.MerchantCustomerId  = "1234";
                customer.PersonalInformation = personalInformation;

                OrderInvoiceData invoiceData = new OrderInvoiceData();
                invoiceData.InvoiceDate   = "20140306191500";
                invoiceData.InvoiceNumber = "000000123";

                OrderReferences references = new OrderReferences();
                references.Descriptor        = "Fast and Furry-ous";
                references.InvoiceData       = invoiceData;
                references.MerchantOrderId   = 123456L;
                references.MerchantReference = "AcmeOrder0001";

                PersonalName shippingName = new PersonalName();
                shippingName.FirstName = "Road";
                shippingName.Surname   = "Runner";
                shippingName.Title     = "Miss";

                AddressPersonal address = new AddressPersonal();
                address.AdditionalInfo = "Suite II";
                address.City           = "Monument Valley";
                address.CountryCode    = "US";
                address.HouseNumber    = "1";
                address.Name           = shippingName;
                address.State          = "Utah";
                address.Street         = "Desertroad";
                address.Zip            = "84536";

                Shipping shipping = new Shipping();
                shipping.Address = address;

                IList <LineItem> items = new List <LineItem>();

                AmountOfMoney item1AmountOfMoney = new AmountOfMoney();
                item1AmountOfMoney.Amount       = 2500L;
                item1AmountOfMoney.CurrencyCode = "EUR";

                LineItemInvoiceData item1InvoiceData = new LineItemInvoiceData();
                item1InvoiceData.Description  = "ACME Super Outfit";
                item1InvoiceData.NrOfItems    = "1";
                item1InvoiceData.PricePerItem = 2500L;

                LineItem item1 = new LineItem();
                item1.AmountOfMoney = item1AmountOfMoney;
                item1.InvoiceData   = item1InvoiceData;

                items.Add(item1);

                AmountOfMoney item2AmountOfMoney = new AmountOfMoney();
                item2AmountOfMoney.Amount       = 480L;
                item2AmountOfMoney.CurrencyCode = "EUR";

                LineItemInvoiceData item2InvoiceData = new LineItemInvoiceData();
                item2InvoiceData.Description  = "Aspirin";
                item2InvoiceData.NrOfItems    = "12";
                item2InvoiceData.PricePerItem = 40L;

                LineItem item2 = new LineItem();
                item2.AmountOfMoney = item2AmountOfMoney;
                item2.InvoiceData   = item2InvoiceData;

                items.Add(item2);

                ShoppingCart shoppingCart = new ShoppingCart();
                shoppingCart.Items = items;

                Order order = new Order();
                order.AmountOfMoney = amountOfMoney;
                order.Customer      = customer;
                order.References    = references;
                order.Shipping      = shipping;
                order.ShoppingCart  = shoppingCart;

                CreatePaymentRequest body = new CreatePaymentRequest();
                body.CardPaymentMethodSpecificInput = cardPaymentMethodSpecificInput;
                body.Order = order;

                try
                {
                    CreatePaymentResponse response = await client.Merchant("merchantId").Payments().Create(body);
                }
                catch (DeclinedPaymentException e)
                {
                    HandleDeclinedPayment(e.CreatePaymentResult);
                }
                catch (ApiException e)
                {
                    HandleApiErrors(e.Errors);
                }
            }
#pragma warning restore 0168
        }
        public async Task TestLoggingCreatePaymentUnicode()
        {
            // POST with a success (201) response
            TestLogger logger = new TestLogger();

            using (MockServer host = new MockServer(Port, "/v1/1234/payments", (request, response, arg3) =>
            {
                AssignResponse((HttpStatusCode)201, new Dictionary <string, string>(), response, "http://localhost/v1/1234/payments/000000123410000595980000100001");

                return(createPaymentUnicodeJson);
            }))
                using (Client client = CreateClient())
                {
                    client.EnableLogging(logger);

                    AmountOfMoney amountOfMoney = new AmountOfMoney();
                    amountOfMoney.CurrencyCode = "CAD";
                    amountOfMoney.Amount       = 2345L;

                    Address billingAddress = new Address();
                    billingAddress.CountryCode = "CA";

                    Customer customer = new Customer();
                    customer.BillingAddress = billingAddress;

                    Order order = new Order();
                    order.AmountOfMoney = amountOfMoney;
                    order.Customer      = customer;

                    Card card = new Card();
                    card.Cvv        = "123";
                    card.CardNumber = "1234567890123456";
                    card.ExpiryDate = "1220";

                    CardPaymentMethodSpecificInput paymentMethodSpecificInput = new CardPaymentMethodSpecificInput();
                    paymentMethodSpecificInput.PaymentProductId = 1;
                    paymentMethodSpecificInput.Card             = card;

                    CreatePaymentRequest request = new CreatePaymentRequest();
                    request.Order = order;
                    request.CardPaymentMethodSpecificInput = paymentMethodSpecificInput;

                    CreatePaymentResponse response = await client.Merchant("1234").Payments().Create(request);

                    Assert.NotNull(response);
                    Assert.NotNull(response.Payment);
                    Assert.NotNull(response.Payment.Id);
                }
            Assert.That(logger.Entries, Has.Count.EqualTo(2));

            TestLoggerEntry requestEntry = logger.Entries.First();

            Assert.That(requestEntry.Message, Is.Not.Null);
            Assert.That(requestEntry.Thrown, Is.Null);

            TestLoggerEntry responseEntry = logger.Entries.ElementAt(1);

            Assert.That(responseEntry.Message, Is.Not.Null);
            Assert.That(responseEntry.Thrown, Is.Null);

            AssertRequestAndResponse(requestEntry.Message, responseEntry.Message, createPaymentUnicodeRequest, createPaymentUnicodeResponse);
        }
        static async Task Main(string[] args)
        {
            try
            {
                string paymentProductId = string.Empty;
                do
                {
                    Console.WriteLine("Enter Payment Product Code");
                    Console.WriteLine("Code | Card Type");
                    Console.WriteLine("1    | Visa");
                    Console.WriteLine("2    | Master Card");
                    paymentProductId = Console.ReadLine();
                } while (string.IsNullOrWhiteSpace(paymentProductId) || !new string[] { "1", "2" }.ToList().Contains(paymentProductId));


                Card card = new Card();
                card.CardNumber = "4567350000427977";
                card.Cvv        = "123";
                card.ExpiryDate = "1220";

                ThreeDSecure threeDSecure = new ThreeDSecure();
                threeDSecure.SkipAuthentication = false;

                CardPaymentMethodSpecificInput cardPaymentMethodSpecificInput = new CardPaymentMethodSpecificInput();
                cardPaymentMethodSpecificInput.Card             = card;
                cardPaymentMethodSpecificInput.PaymentProductId = paymentProductId == "2" ? 3 : 1;
                cardPaymentMethodSpecificInput.ThreeDSecure     = threeDSecure;

                AmountOfMoney amountOfMoney = new AmountOfMoney();
                amountOfMoney.Amount       = 1;
                amountOfMoney.CurrencyCode = "USD";

                Address billingAddress = new Address();
                billingAddress.CountryCode = "US";

                Customer customer = new Customer();
                customer.BillingAddress     = billingAddress;
                customer.MerchantCustomerId = "1378";

                Order order = new Order();
                order.AmountOfMoney = amountOfMoney;
                order.Customer      = customer;

                CreatePaymentRequest body = new CreatePaymentRequest();
                body.CardPaymentMethodSpecificInput = cardPaymentMethodSpecificInput;
                body.Order = order;

                try
                {
                    using (Client client = GetClient())
                    {
                        CreatePaymentResponse response = await client.Merchant("1378").Payments().Create(body);

                        Console.WriteLine("Id: " + response.Payment.Id);
                        Console.WriteLine("Status: " + response.Payment.Status);
                        Console.WriteLine("AmountOfMoney: " + response.Payment.PaymentOutput.AmountOfMoney);
                    }
                }
                catch (DeclinedPaymentException e)
                {
                    Console.WriteLine("Error: Payment Declined");
                    foreach (var error in e.Errors)
                    {
                        Console.WriteLine("Code: " + error.Code);
                        Console.WriteLine("PropertyName: " + error.PropertyName);
                        Console.WriteLine("Message: " + error.Message);
                    }
                }
                catch (ApiException e)
                {
                    Console.WriteLine("Error: Unknown error occured");
                    foreach (var error in e.Errors)
                    {
                        Console.WriteLine("Code: " + error.Code);
                        Console.WriteLine("PropertyName: " + error.PropertyName);
                        Console.WriteLine("Message: " + error.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadLine();
        }