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"];

            PaysafeApiClient client = new PaysafeApiClient(apiKey, apiSecret, Paysafe.Environment.TEST, accountNumber);

            try
            {
                Purchases purchase = Purchases.Builder()
                                     .merchantRefNum(Request.Form["merchant_customer_id"])
                                     .amount(Convert.ToInt32(Double.Parse(Request.Form["amount"])))
                                     .ach()
                                     .accountHolderName(Request.Form["account_holder_name"])
                                     .accountNumber(Request.Form["account_number"])
                                     .accountType(Request.Form["account_type"])
                                     .routingNumber(Request.Form["routing_number"])
                                     .payMethod(Request.Form["pay_method"])
                                     .Done()
                                     .customerIp(Request.Form["customer_ip"])
                                     .profile()
                                     .firstName(Request.Form["first_name"])
                                     .lastName(Request.Form["last_name"])
                                     .email(Request.Form["email"])
                                     .Done()
                                     .billingDetails()
                                     .street(Request.Form["street"])
                                     .city(Request.Form["city"])
                                     .state(Request.Form["state"])
                                     .country(Request.Form["country"])
                                     .zip(Request.Form["zip"])
                                     .phone(Request.Form["phone"])
                                     .Done()
                                     .Build();
                Purchases response = client.directDebitService().submit(purchase);
                this.response = response.ToString();
            }
            catch (Exception ex)
            {
                Response.Write("<font style=\"color: #FF0000;\">Error Message is : " + ex.Message + "</font>\n");
            }
        }
Ejemplo n.º 2
0
        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"];
                    PaysafeApiClient client        = new PaysafeApiClient(apiKey, apiSecret, Paysafe.Environment.TEST, accountNumber);

                    Paysafe.CustomerVault.Profile profile = client.customerVaultService().create(
                        Paysafe.CustomerVault.Profile.Builder()
                        .merchantCustomerId(System.Guid.NewGuid().ToString())
                        .locale("en_US")
                        .firstName("John")
                        .lastName("Smith")
                        .email("*****@*****.**")
                        .phone("713-444-5555")
                        .Build());

                    Paysafe.CustomerVault.Address address = client.customerVaultService().create(
                        Paysafe.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());

                    Paysafe.CustomerVault.ACHBankAccounts account = client.customerVaultService().create(
                        Paysafe.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"];
                    PaysafeApiClient client        = new PaysafeApiClient(apiKey, apiSecret, Paysafe.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"];
                    PaysafeApiClient client        = new PaysafeApiClient(apiKey, apiSecret, Paysafe.Environment.TEST, accountNumber);

                    Paysafe.CustomerVault.Profile profile = client.customerVaultService().create(
                        Paysafe.CustomerVault.Profile.Builder()
                        .merchantCustomerId(System.Guid.NewGuid().ToString())
                        .locale("en_US")
                        .firstName("John")
                        .lastName("Smith")
                        .email("*****@*****.**")
                        .phone("713-444-5555")
                        .Build());

                    Paysafe.CustomerVault.Address address = client.customerVaultService().create(
                        Paysafe.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());

                    Paysafe.CustomerVault.EFTBankAccounts account = client.customerVaultService().create(
                        Paysafe.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"];
                    PaysafeApiClient client        = new PaysafeApiClient(apiKey, apiSecret, Paysafe.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");
            }
        }