Skip to content

Commit 4967091

Browse files
author
akankaria
committed
Adding sample codes for Q4 API updates
1 parent 9cb3869 commit 4967091

5 files changed

Lines changed: 86 additions & 1 deletion

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
}

SampleCode.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Text;
77
using System.Threading.Tasks;
8+
using net.authorize.sample.CustomerProfiles;
89

910
namespace net.authorize.sample
1011
{
@@ -123,6 +124,7 @@ private static void ShowMethods()
123124
Console.WriteLine(" GetTransactionDetails");
124125
Console.WriteLine(" GetTransactionList");
125126
Console.WriteLine(" UpdateSplitTenderGroup");
127+
Console.WriteLine(" GetHostedPaymentPage");
126128
}
127129

128130
private static void RunMethod(String methodName)
@@ -313,6 +315,9 @@ private static void RunMethod(String methodName)
313315
case "UpdateSplitTenderGroup":
314316
UpdateSplitTenderGroup.Run(apiLoginId, transactionKey);
315317
break;
318+
case "GetHostedPaymentPage":
319+
GetHostedPaymentPage.Run(apiLoginId, transactionKey, 12.23m);
320+
break;
316321
default:
317322
ShowUsage();
318323
break;

SampleCode.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<Reference Include="System.Xml" />
4545
</ItemGroup>
4646
<ItemGroup>
47+
<Compile Include="CustomerProfiles\GetHostedPaymentPage.cs" />
4748
<Compile Include="MobileInappTransactions\CreateAnAcceptTransaction.cs" />
4849
<Compile Include="MobileInappTransactions\CreateAnAndroidPayTransaction.cs" />
4950
<Compile Include="MobileInappTransactions\CreateAnApplePayTransaction.cs" />

SampleCodeTest/SampleCodeList.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ GetSubscriptionStatus 1 1
5151
GetSubscription 1 1
5252
UpdateSubscription 1 1
5353
CreateCustomerProfile 1 1
54-
CreateCustomerPaymentProfile 1 1
54+
CreateCustomerPaymentProfile 1 1
55+
GetHostedPaymentPage 1 1

SampleCodeTest/TestRunner.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using AuthorizeNet;
1010
using net.authorize.sample.PaymentTransactions;
1111
using System.Threading;
12+
using net.authorize.sample.CustomerProfiles;
1213
using net.authorize.sample.MobileInappTransactions;
1314

1415
namespace SampleCodeTest
@@ -424,5 +425,10 @@ public ANetApiResponse TestCreateAnAcceptTransaction()
424425
var response = (createTransactionResponse)CreateAnAcceptTransaction.Run(apiLoginId, transactionKey, GetAmount());
425426
return response;
426427
}
428+
429+
public ANetApiResponse TestGetHostedPaymentPage()
430+
{
431+
return GetHostedPaymentPage.Run(apiLoginId, transactionKey, GetAmount());
432+
}
427433
}
428434
}

0 commit comments

Comments
 (0)