forked from AuthorizeNet/sample-code-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateSubscription.cs
78 lines (67 loc) · 2.75 KB
/
UpdateSubscription.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using AuthorizeNet.Api.Controllers;
using AuthorizeNet.Api.Contracts.V1;
using AuthorizeNet.Api.Controllers.Bases;
namespace net.authorize.sample
{
class UpdateSubscription
{
public static void Run(string ApiLoginID, string ApiTransactionKey)
{
Console.WriteLine("Update Subscription Sample");
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;
ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
{
name = ApiLoginID,
ItemElementName = ItemChoiceType.transactionKey,
Item = ApiTransactionKey,
};
paymentScheduleType schedule = new paymentScheduleType
{
startDate = DateTime.Now.AddDays(1), // start date should be tomorrow
totalOccurrences = 9999 // 999 indicates no end date
};
#region Payment Information
var creditCard = new creditCardType
{
cardNumber = "4111111111111111",
expirationDate = "0718"
};
//standard api call to retrieve response
paymentType cc = new paymentType { Item = creditCard };
#endregion
nameAndAddressType addressInfo = new nameAndAddressType()
{
firstName = "Calvin",
lastName = "Brown"
};
ARBSubscriptionType subscriptionType = new ARBSubscriptionType()
{
amount = 35.55m,
paymentSchedule = schedule,
billTo = addressInfo,
payment = cc
};
//Please change the subscriptionId according to your request
var request = new ARBUpdateSubscriptionRequest { subscription = subscriptionType, subscriptionId = "2787902" };
var controller = new ARBUpdateSubscriptionController(request);
controller.Execute();
ARBUpdateSubscriptionResponse response = controller.GetApiResponse();
//validate
if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
{
if (response != null && response.messages.message != null)
{
Console.WriteLine("Success, RefID Code : " + response.refId);
}
}
else
{
Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text);
}
}
}
}