/// <summary>
        /// # STEP 1 -- From Guide
        /// </summary>
        public EwayCustomerDetails CreateCustomerWithPaymentRequirement(string redirectUrl, bool redirect, EwayCustomerDetails customer, EwayPayment payment)
        {
            var mode = redirect ? ResponseMode.Redirect : ResponseMode.Return;

            if (string.IsNullOrWhiteSpace(redirectUrl)) throw new ArgumentNullException("redirectUrl", "eWAY requires a redirect url");

            if (payment.TotalAmount <= 0) throw new ArgumentNullException("payment", "payment.TotalAmount requires a value larger than 0");

            var auth = GetAuthenticationFromConfiguration();

            using (var service = new RapidAPISoapClient())
            {
                // When the SaveToken field is set to “true”, and the TokenCustomerID 
                // field is empty, a new Token customer will be created once the payment has been submitted.
                var response = service.CreateAccessCode(new CreateAccessCodeRequest
                    {
                        Authentication = auth,
                        Customer = new Customer
                            {
                                Title = customer.Title,
                                FirstName = customer.FirstName,
                                LastName = customer.LastName,
                                Country = customer.Country.ToLower(),
                                SaveToken = true,
                                TokenCustomerID = null,
                            },
                        RedirectUrl = redirectUrl,
                        ResponseMode = mode,
                        Payment = new Payment
                            {
                                InvoiceDescription = payment.InvoiceDescription,
                                InvoiceNumber = payment.InvoiceNumber,
                                InvoiceReference = payment.InvoiceReference,
                                TotalAmount = payment.TotalAmount
                            }
                    });

                return new EwayCustomerDetails
                    {
                        // Token will not exist yet
                        Token = response.Customer.TokenCustomerID.ToString(),
                        AccessCode = response.AccessCode
                    };
            }
        }
Пример #2
0
        public BuyController()
        {
            // TODO: make this constructor injected
            _eway = new EwayPaymentGateway();

            // TODO: this won't exist here, this is up to you to manage in your system.
            _customer = new EwayCustomerDetails
            {
                Title = "Mr.",
                FirstName = "Just",
                LastName = "SetupTheCustomer",
                Country = "au",
            };

            _payment = new EwayPayment
            {
                InvoiceDescription = "Customer Created",
                InvoiceNumber = Guid.NewGuid().ToString(),
                InvoiceReference = Guid.NewGuid().ToString(),
                TotalAmount = DateTime.Now.Minute * 100
            };
        }
        public string ChargeExistingCustomer(string token, EwayPayment payment)
        {
            var auth = GetAuthenticationFromConfiguration();

            using (var service = new RapidAPISoapClient())
            {
                // When the SaveToken field is set to “true”, and the TokenCustomerID 
                // field is empty, a new Token customer will be created once the payment has been submitted.
                var response = service.CreateAccessCode(
                        new CreateAccessCodeRequest
                            {
                                Authentication = auth,
                                ResponseMode = ResponseMode.Return,
                                RedirectUrl = "http://google.com/why-would-you-think-I-only-come-from-the-web",
                                Customer = new Customer
                                    {
                                        TokenCustomerID = Int64.Parse(token)
                                    },
                                Payment =
                                    new Payment
                                        {
                                            InvoiceDescription = payment.InvoiceDescription,
                                            InvoiceNumber = payment.InvoiceNumber,
                                            InvoiceReference = payment.InvoiceReference,
                                            TotalAmount = payment.TotalAmount
                                        }
                            });

                //return response.AccessCode;

                var outcome = GetAccessCodeResult(response.AccessCode);

                return outcome.ResponseMessage;
            }
        }