/// <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 }; } }
/// <summary> /// # STEP 3 -- From Guide /// </summary> public EwayResponse GetAccessCodeResult(GetAccessCodeResultRequest request) { // Create a new instance of the RapidAPI service and send the request using (var service = new RapidAPISoapClient()) { var response = service.GetAccessCodeResult(request); if (string.Compare(response.ResponseCode, "00", true, CultureInfo.CurrentCulture) != 0) { var msg = string.Format("Payment Unsuccessful {2} Response Code:{0}{2}ResponseMessage:{1}{2}", response.ResponseCode, response.ResponseMessage, Environment.NewLine); throw new EwayPaymentException(msg); } return CreateResponse(response); } }
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; } }