protected void submit(object sender, System.EventArgs e) { string apiKey = System.Configuration.ConfigurationManager.AppSettings["ApiKey"]; string apiSecret = System.Configuration.ConfigurationManager.AppSettings["ApiSecret"]; string accountNumber = System.Configuration.ConfigurationManager.AppSettings["accountNumber"]; OptimalApiClient client = new OptimalApiClient(apiKey, apiSecret, OptimalPayments.Environment.TEST, accountNumber); try { Profile profile = client.customerVaultService().create(Profile.Builder() .merchantCustomerId(System.Guid.NewGuid().ToString()) .locale("en_US") .firstName("John") .lastName("Smith") .email("*****@*****.**") .phone("713-444-5555") .Build()); Address address = client.customerVaultService().create(Address.Builder() .nickName("home") .street("100 Queen Street West") .street2("Unit 201") .city("Toronto") .country("CA") .state("ON") .zip("M5H 2N2") .recipientName("Jane Doe") .phone("647-788-3901") .profileId(profile.id()) .Build()); List <Mandates> mandateList = new List <Mandates>(); Mandates mandate = Mandates.Builder() .reference("SUBCRIP35") .Build(); mandateList.Add(mandate); SEPABankAccounts account = client.customerVaultService().create(SEPABankAccounts.Builder() .iban(Request.Form["iban"]) .bic(Request.Form["bic"]) .mandates(mandateList) .accountHolderName(Request.Form["account_holder_name"]) .nickName(Request.Form["nick_name"]) .billingAddressId(address.id()) .profileId(profile.id()) .Build()); this.response = account.ToString(); } catch (Exception ex) { Response.Write("<font style=\"color: #FF0000;\">Error Message is : " + ex.Message + "</font>\n"); } }
protected void submit(object sender, System.EventArgs e) { string apiKey = System.Configuration.ConfigurationManager.AppSettings["ApiKey"]; string apiSecret = System.Configuration.ConfigurationManager.AppSettings["ApiSecret"]; string accountNumber = System.Configuration.ConfigurationManager.AppSettings["accountNumber"]; int currencyBaseUnitsMultiplier = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["CurrencyBaseUnitsMultiplier"]); OptimalApiClient client = new OptimalApiClient(apiKey, apiSecret, OptimalPayments.Environment.TEST, accountNumber); Profile profile = client.customerVaultService().create(Profile.Builder() .merchantCustomerId(Request.Form["merchant_customer_id"]) .locale("en_US") .firstName(Request.Form["first_name"]) .lastName(Request.Form["last_name"]) .email(Request.Form["email"]) .Build()); Address address = client.customerVaultService().create(Address.Builder() .nickName("home") .street(Request.Form["street"]) .city(Request.Form["city"]) .state(Request.Form["state"]) .country(Request.Form["country"]) .zip(Request.Form["zip"]) .profileId(profile.id()) .Build()); Card card = client.customerVaultService().create(Card.Builder() .cardNum(Request.Form["card_number"]) .cardExpiry() .month(Convert.ToInt32(Request.Form["card_expiry_month"])) .year(Convert.ToInt32(Request.Form["card_expiry_year"])) .Done() .billingAddressId(address.id()) .profileId(profile.id()) .Build()); Authorization auth = client.cardPaymentService().authorize(Authorization.Builder() .merchantRefNum(Request.Form["merchant_ref_num"]) .amount(Convert.ToInt32(Double.Parse(Request.Form["amount"]) * currencyBaseUnitsMultiplier)) .settleWithAuth(true) .card() .paymentToken(card.paymentToken()) .Done() .Build()); this.payment_id = auth.id(); }
protected void submit(object sender, System.EventArgs e) { string apiKey = System.Configuration.ConfigurationManager.AppSettings["ApiKey"]; string apiSecret = System.Configuration.ConfigurationManager.AppSettings["ApiSecret"]; try { string val = radio.SelectedItem.Value.ToString(); if (val.Equals("ACH")) { string accountNumber = System.Configuration.ConfigurationManager.AppSettings["AccountNumber_ACH"]; OptimalApiClient client = new OptimalApiClient(apiKey, apiSecret, OptimalPayments.Environment.TEST, accountNumber); OptimalPayments.CustomerVault.Profile profile = client.customerVaultService().create( OptimalPayments.CustomerVault.Profile.Builder() .merchantCustomerId(System.Guid.NewGuid().ToString()) .locale("en_US") .firstName("John") .lastName("Smith") .email("*****@*****.**") .phone("713-444-5555") .Build()); OptimalPayments.CustomerVault.Address address = client.customerVaultService().create( OptimalPayments.CustomerVault.Address.Builder() .nickName("home") .street("100 Queen Street West") .street2("Unit 201") .city("Toronto") .country("CA") .state("ON") .zip("M5H 2N2") .recipientName("Jane Doe") .phone("647-788-3901") .profileId(profile.id()) .Build()); OptimalPayments.CustomerVault.ACHBankAccounts account = client.customerVaultService().create( OptimalPayments.CustomerVault.ACHBankAccounts.Builder() .nickName("Johns RBC Business Bank Account") .accountNumber(getRandomNumber()) .routingNumber("123456789") .accountHolderName("XYZ Business") .billingAddressId(address.id()) .accountType("CHECKING") .merchantRefNum(System.Guid.NewGuid().ToString()) .profileId(profile.id()) .Build()); Purchases purchase = Purchases.Builder() .merchantRefNum(Request.Form["merchant_customer_id"]) .amount(Convert.ToInt32(Double.Parse(Request.Form["amount"]))) .ach() .paymentToken(account.paymentToken()) .payMethod("WEB") .Done() .Build(); Purchases response = client.directDebitService().submit(purchase); this.response = response.ToString(); } else if (val.Equals("BACS")) { string accountNumber = System.Configuration.ConfigurationManager.AppSettings["AccountNumber_BACS"]; OptimalApiClient client = new OptimalApiClient(apiKey, apiSecret, OptimalPayments.Environment.TEST, accountNumber); Purchases purchase = Purchases.Builder() .merchantRefNum(Request.Form["merchant_customer_id"]) .amount(Convert.ToInt32(Double.Parse(Request.Form["amount"]))) .bacs() .paymentToken(Request.Form["payment_token"]) .Done() .Build(); Purchases response = client.directDebitService().submit(purchase); this.response = response.ToString(); } else if (val.Equals("EFT")) { string accountNumber = System.Configuration.ConfigurationManager.AppSettings["AccountNumber_EFT"]; OptimalApiClient client = new OptimalApiClient(apiKey, apiSecret, OptimalPayments.Environment.TEST, accountNumber); OptimalPayments.CustomerVault.Profile profile = client.customerVaultService().create( OptimalPayments.CustomerVault.Profile.Builder() .merchantCustomerId(System.Guid.NewGuid().ToString()) .locale("en_US") .firstName("John") .lastName("Smith") .email("*****@*****.**") .phone("713-444-5555") .Build()); OptimalPayments.CustomerVault.Address address = client.customerVaultService().create( OptimalPayments.CustomerVault.Address.Builder() .nickName("home") .street("100 Queen Street West") .street2("Unit 201") .city("Toronto") .country("CA") .state("ON") .zip("M5H 2N2") .recipientName("Jane Doe") .phone("647-788-3901") .profileId(profile.id()) .Build()); OptimalPayments.CustomerVault.EFTBankAccounts account = client.customerVaultService().create( OptimalPayments.CustomerVault.EFTBankAccounts.Builder() .accountNumber(getRandomNumber()) .transitNumber("11224") .institutionId("123") .accountHolderName("John Smith") .nickName("Johns RBC Business Bank Account") .billingAddressId(address.id()) .profileId(profile.id()) .Build()); Purchases response = client.directDebitService().submit(Purchases.Builder() .merchantRefNum(System.Guid.NewGuid().ToString()) .amount(10038) .eft() .paymentToken(account.paymentToken()) .Done() .Build() ); this.response = response.ToString(); } else if (val.Equals("SEPA")) { string accountNumber = System.Configuration.ConfigurationManager.AppSettings["AccountNumber_SEPA"]; OptimalApiClient client = new OptimalApiClient(apiKey, apiSecret, OptimalPayments.Environment.TEST, accountNumber); Purchases response = client.directDebitService().submit(Purchases.Builder() .merchantRefNum(System.Guid.NewGuid().ToString()) .amount(10038) .sepa() .paymentToken(Request.Form["payment_token"]) .Done() .Build() ); this.response = response.ToString(); } } catch (Exception ex) { Response.Write("<font style=\"color: #FF0000;\">Error Message is : " + ex.Message + "</font>\n"); } }