-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathHomeController.cs
172 lines (129 loc) · 5.91 KB
/
HomeController.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using CyberSource.Api;
using CyberSource.Model;
using System;
using System.Collections.Generic;
using System.Web.Mvc;
namespace flex_microform_sample.Controllers
{
public class HomeController : Controller
{
public ActionResult Checkout()
{
// Call the .NET CyberSource SDK to generate the Flex Key
ViewBag.Jwk = "{\"kid\":\"HKJHKJ\"}";
/**
* Generating Capture Context Request Payload
* Defining Encryption Type = RsaOaep
* Defining TargetOrigin = http://localhost:65309 or http://localhost:8080
*
*/
var requestObj = new GeneratePublicKeyRequest("RsaOaep256", "http://localhost:65309 http://localhost:8080");
try
{
var configDictionary = new Configuration().GetConfiguration();
var clientConfig = new CyberSource.Client.Configuration(merchConfigDictObj: configDictionary);
var apiInstance = new KeyGenerationApi(clientConfig);
/**
* Initiating public Key request
* query paramiter set to format=JWT for Flex 11
*/
var result = apiInstance.GeneratePublicKey(requestObj, "JWT");
Console.WriteLine(result);
Console.WriteLine(result.KeyId);
ViewBag.Jwk = result.KeyId;
}
catch (Exception e)
{
Console.WriteLine("Exception on calling the API: " + e.Message);
}
return View();
}
public ActionResult Receipt()
{
dynamic flexObj = Request.Params["flexResponse"];
/**
* Processing Authorization Request
* Code developed from CyberSource Rest Samples csharp
* https://github.com/CyberSource/cybersource-rest-samples-csharp
*/
var processingInformationObj = new Ptsv2paymentsProcessingInformation() { CommerceIndicator = "internet" };
var clientReferenceInformationObj = new Ptsv2paymentsClientReferenceInformation { Code = "test_payment" };
var orderInformationObj = new Ptsv2paymentsOrderInformation();
var billToObj = new Ptsv2paymentsOrderInformationBillTo
{
Country = "US",
FirstName = "John",
LastName = "Doe",
Address1 = "1 Market St",
PostalCode = "94105",
Locality = "San Francisco",
AdministrativeArea = "CA",
Email = "[email protected]"
};
orderInformationObj.BillTo = billToObj;
var amountDetailsObj = new Ptsv2paymentsOrderInformationAmountDetails
{
TotalAmount = "102.21",
Currency = "USD"
};
orderInformationObj.AmountDetails = amountDetailsObj;
// Passing Transient token
var transientTokenObj = new Ptsv2paymentsTokenInformation { TransientTokenJwt = flexObj };
var requestObj = new CreatePaymentRequest
{
ProcessingInformation = processingInformationObj,
ClientReferenceInformation = clientReferenceInformationObj,
OrderInformation = orderInformationObj,
TokenInformation = transientTokenObj
};
try
{
var configDictionary = new Configuration().GetConfiguration();
var clientConfig = new CyberSource.Client.Configuration(merchConfigDictObj: configDictionary);
var apiInstance = new PaymentsApi(clientConfig);
var result = apiInstance.CreatePayment(requestObj);
Console.WriteLine(result);
//Making response pretty & passing to page
ViewBag.paymentResponse =result;
}
catch (Exception e)
{
Console.WriteLine("Exception on calling the API: " + e.Message);
return null;
}
return View();
}
public ActionResult Token()
{
//dynamic flexObj = JValue.Parse(Request.Params["flexResponse"]);
dynamic flexObj = Request.Params["flexResponse"];
ViewBag.JWT = flexObj.Replace("\r\n", "").Replace("\"", "");
return View();
}
}
public class Configuration
{
// initialize dictionary object
private readonly Dictionary<string, string> _configurationDictionary = new Dictionary<string, string>();
public Dictionary<string, string> GetConfiguration()
{
_configurationDictionary.Add("authenticationType", "HTTP_SIGNATURE");
_configurationDictionary.Add("merchantID", "testrest");
_configurationDictionary.Add("merchantsecretKey", "yBJxy6LjM2TmcPGu+GaJrHtkke25fPpUX+UY6/L/1tE=");
_configurationDictionary.Add("merchantKeyId", "08c94330-f618-42a3-b09d-e1e43be5efda");
_configurationDictionary.Add("keysDirectory", "Resource");
_configurationDictionary.Add("keyFilename", "testrest");
_configurationDictionary.Add("runEnvironment", "cybersource.environment.sandbox");
_configurationDictionary.Add("keyAlias", "testrest");
_configurationDictionary.Add("keyPass", "testrest");
_configurationDictionary.Add("enableLog", "FALSE");
_configurationDictionary.Add("logDirectory", string.Empty);
_configurationDictionary.Add("logFileName", string.Empty);
_configurationDictionary.Add("logFileMaxSize", "5242880");
_configurationDictionary.Add("timeout", "1000");
_configurationDictionary.Add("proxyAddress", string.Empty);
_configurationDictionary.Add("proxyPort", string.Empty);
return _configurationDictionary;
}
}
}