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); }
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); }
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 }
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(); }