/
simple-authorizationinternet.js
88 lines (72 loc) · 3.29 KB
/
simple-authorizationinternet.js
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
'use strict';
var cybersourceRestApi = require('cybersource-rest-client');
var path = require('path');
var filePath = path.resolve('Data/Configuration.js');
var configuration = require(filePath);
function simple_authorization_internet(callback, enable_capture) {
try {
var configObject = new configuration();
var apiClient = new cybersourceRestApi.ApiClient();
var requestObj = new cybersourceRestApi.CreatePaymentRequest();
var clientReferenceInformation = new cybersourceRestApi.Ptsv2paymentsClientReferenceInformation();
clientReferenceInformation.code = 'TC50171_3';
requestObj.clientReferenceInformation = clientReferenceInformation;
var processingInformation = new cybersourceRestApi.Ptsv2paymentsProcessingInformation();
processingInformation.capture = false;
if (enable_capture === true) {
processingInformation.capture = true;
}
requestObj.processingInformation = processingInformation;
var paymentInformation = new cybersourceRestApi.Ptsv2paymentsPaymentInformation();
var paymentInformationCard = new cybersourceRestApi.Ptsv2paymentsPaymentInformationCard();
paymentInformationCard.number = '4111111111111111';
paymentInformationCard.expirationMonth = '12';
paymentInformationCard.expirationYear = '2031';
paymentInformation.card = paymentInformationCard;
requestObj.paymentInformation = paymentInformation;
var orderInformation = new cybersourceRestApi.Ptsv2paymentsOrderInformation();
var orderInformationAmountDetails = new cybersourceRestApi.Ptsv2paymentsOrderInformationAmountDetails();
orderInformationAmountDetails.totalAmount = '50.00';
orderInformationAmountDetails.currency = 'USD';
orderInformation.amountDetails = orderInformationAmountDetails;
var orderInformationBillTo = new cybersourceRestApi.Ptsv2paymentsOrderInformationBillTo();
orderInformationBillTo.firstName = 'John';
orderInformationBillTo.lastName = 'Doe';
orderInformationBillTo.address1 = '1 Market St';
orderInformationBillTo.locality = 'san francisco';
orderInformationBillTo.administrativeArea = 'CA';
orderInformationBillTo.postalCode = '94105';
orderInformationBillTo.country = 'US';
orderInformationBillTo.email = 'test@cybs.com';
orderInformationBillTo.phoneNumber = '4158880000';
orderInformation.billTo = orderInformationBillTo;
requestObj.orderInformation = orderInformation;
var instance = new cybersourceRestApi.PaymentsApi(configObject, apiClient);
instance.createPayment(requestObj, function (error, data, response) {
if (error) {
console.log('\nError : ' + JSON.stringify(error));
}
else if (data) {
console.log('\nData : ' + JSON.stringify(data));
}
console.log('\nResponse : ' + JSON.stringify(response));
console.log('\nResponse Code of Process a Payment : ' + JSON.stringify(response['status']));
var status = response['status'];
write_log_audit(status);
callback(error, data, response);
});
}
catch (error) {
console.log('\nException on calling the API : ' + error);
}
}
function write_log_audit(status) {
var filename = path.basename(__filename).split(".")[0];
console.log(`[Sample Code Testing] [${filename}] ${status}`);
}
if (require.main === module) {
simple_authorization_internet(function () {
console.log('\nCreatePayment end.');
});
}
module.exports.simple_authorization_internet = simple_authorization_internet;