|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using AuthorizeNet.Api.Contracts.V1; |
| 6 | +using AuthorizeNet.Api.Controllers; |
| 7 | +using AuthorizeNet.Api.Controllers.Bases; |
| 8 | + |
| 9 | +namespace net.authorize.sample.CustomerProfiles |
| 10 | +{ |
| 11 | + public class GetHostedPaymentPage |
| 12 | + { |
| 13 | + public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal amount) |
| 14 | + { |
| 15 | + Console.WriteLine("GetHostedPaymentPage Sample"); |
| 16 | + ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX; |
| 17 | + ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType() |
| 18 | + { |
| 19 | + name = ApiLoginID, |
| 20 | + ItemElementName = ItemChoiceType.transactionKey, |
| 21 | + Item = ApiTransactionKey, |
| 22 | + }; |
| 23 | + |
| 24 | + var creditCard = new creditCardType |
| 25 | + { |
| 26 | + cardNumber = "4111111111111111", |
| 27 | + expirationDate = "0718", |
| 28 | + cardCode = "123" |
| 29 | + }; |
| 30 | + |
| 31 | + //standard api call to retrieve response |
| 32 | + var paymentType = new paymentType { Item = creditCard }; |
| 33 | + |
| 34 | + settingType[] settings = new settingType[]{ new settingType() }; |
| 35 | + settings[0].settingName = settingNameEnum.hostedPaymentReturnOptions.ToString(); |
| 36 | + settings[0].settingValue = "https://returnurl.com/return/"; |
| 37 | + |
| 38 | + var transactionRequest = new transactionRequestType |
| 39 | + { |
| 40 | + transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // authorize capture only |
| 41 | + amount = amount, |
| 42 | + payment = paymentType |
| 43 | + }; |
| 44 | + |
| 45 | + var request = new getHostedPaymentPageRequest(); |
| 46 | + request.transactionRequest = transactionRequest; |
| 47 | + request.hostedPaymentSettings = settings; |
| 48 | + |
| 49 | + // instantiate the contoller that will call the service |
| 50 | + var controller = new getHostedPaymentPageController(request); |
| 51 | + controller.Execute(); |
| 52 | + |
| 53 | + // get the response from the service (errors contained if any) |
| 54 | + var response = controller.GetApiResponse(); |
| 55 | + |
| 56 | + //validate |
| 57 | + if (response != null && response.messages.resultCode == messageTypeEnum.Ok) |
| 58 | + { |
| 59 | + Console.WriteLine("Message code : " + response.messages.message[0].code); |
| 60 | + Console.WriteLine("Message text : " + response.messages.message[0].text); |
| 61 | + Console.WriteLine("Token : " + response.token); |
| 62 | + } |
| 63 | + else if (response != null) |
| 64 | + { |
| 65 | + Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); |
| 66 | + Console.WriteLine("Failed to get hosted payment page"); |
| 67 | + } |
| 68 | + |
| 69 | + return response; |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments