/// <summary> /// Handle GetPaymentOptions API call /// </summary> /// <param name="context"></param> private void GetPaymentOptions(HttpContext context) { NameValueCollection parameters = context.Request.Params; GetPaymentOptionsRequest req = new GetPaymentOptionsRequest( new RequestEnvelope("en_US"), parameters["payKey"]); // All set. Fire the request AdaptivePaymentsService service = new AdaptivePaymentsService(); GetPaymentOptionsResponse resp = null; try { resp = service.GetPaymentOptions(req); } catch (System.Exception e) { context.Response.Write(e.Message); return; } // Display response values. Dictionary<string, string> keyResponseParams = new Dictionary<string, string>(); string redirectUrl = null; if (!(resp.responseEnvelope.ack == AckCode.FAILURE) && !(resp.responseEnvelope.ack == AckCode.FAILUREWITHWARNING)) { int idx = 1; foreach(ReceiverOptions option in resp.receiverOptions) { keyResponseParams.Add("Receiver option " + idx, option.description); keyResponseParams.Add("Receiver email " + idx, option.receiver.email); idx++; } if(resp.displayOptions != null) { keyResponseParams.Add("Business name", resp.displayOptions.businessName); keyResponseParams.Add("Header image", resp.displayOptions.headerImageUrl); keyResponseParams.Add("Email header image", resp.displayOptions.emailHeaderImageUrl); } keyResponseParams.Add("Shipping address Id", resp.shippingAddressId); } displayResponse(context, "GetPaymentOptions", keyResponseParams, service.getLastRequest(), service.getLastResponse(), resp.error, redirectUrl); }
// # GetPaymentOptions API Operation // You use the GetPaymentOptions API operation to retrieve the payment options passed with the SetPaymentOptionsRequest. public GetPaymentOptionsResponse GetPaymentOptionsAPIOperation() { // Create the GetPaymentOptionsResponse object GetPaymentOptionsResponse responseGetPaymentOptions = new GetPaymentOptionsResponse(); try { // Request envelope object RequestEnvelope envelopeRequest = new RequestEnvelope(); // The code for the language in which errors are returned envelopeRequest.errorLanguage = "en_US"; // GetPaymentOptionsRequest which takes, // // * `Request Envelope` - Information common to each API operation, such // as the language in which an error message is returned. // * `Pay Key` - The pay key that identifies the payment for which you // want to set payment options. This is the pay key returned in the // PayResponse message. Action Type in PayRequest must be `CREATE` GetPaymentOptionsRequest getPaymentOptionsRequest = new GetPaymentOptionsRequest( envelopeRequest, "AP-1VB65877N5917862M"); // Create the service wrapper object to make the API call AdaptivePaymentsService service = new AdaptivePaymentsService(); // # API call // Invoke the GetPaymentOptions method in service wrapper object responseGetPaymentOptions = service.GetPaymentOptions(getPaymentOptionsRequest); // Response envelope acknowledgement string acknowledgement = "GetPaymentOptions API Operation - "; acknowledgement += responseGetPaymentOptions.responseEnvelope.ack.ToString(); logger.Info(acknowledgement + "\n"); Console.WriteLine(acknowledgement + "\n"); // # Success values if (responseGetPaymentOptions.responseEnvelope.ack.ToString().Trim().ToUpper().Equals("SUCCESS")) { // Response envelope acknowledgement acknowledgement = responseGetPaymentOptions.responseEnvelope.ack.ToString().Trim().ToUpper(); logger.Info(acknowledgement + "\n"); Console.WriteLine(acknowledgement + "\n"); // # Success values if (acknowledgement.Equals("SUCCESS")) { // Business Name you set in SetPaymentOptions logger.Info("Business Name : " + responseGetPaymentOptions.displayOptions.businessName + "\n"); Console.WriteLine("Business Name : " + responseGetPaymentOptions.displayOptions.businessName + "\n"); } // # Error Values else { List <ErrorData> errorMessages = responseGetPaymentOptions.error; foreach (ErrorData error in errorMessages) { logger.Debug("API Error Message : " + error.message); Console.WriteLine("API Error Message : " + error.message + "\n"); } } } } // # Exception log catch (System.Exception ex) { // Log the exception message logger.Debug("Error Message : " + ex.Message); Console.WriteLine("Error Message : " + ex.Message); } return(responseGetPaymentOptions); }