/
credit.js
81 lines (67 loc) · 3.01 KB
/
credit.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
'use strict';
var cybersourceRestApi = require('cybersource-rest-client');
var path = require('path');
var filePath = path.resolve('Data/Configuration.js');
var configuration = require(filePath);
function credit(callback) {
try {
var configObject = new configuration();
var apiClient = new cybersourceRestApi.ApiClient();
var requestObj = new cybersourceRestApi.CreateCreditRequest();
var clientReferenceInformation = new cybersourceRestApi.Ptsv2paymentsClientReferenceInformation();
clientReferenceInformation.code = '12345678';
requestObj.clientReferenceInformation = clientReferenceInformation;
var paymentInformation = new cybersourceRestApi.Ptsv2paymentsidrefundsPaymentInformation();
var paymentInformationCard = new cybersourceRestApi.Ptsv2paymentsidrefundsPaymentInformationCard();
paymentInformationCard.number = '4111111111111111';
paymentInformationCard.expirationMonth = '03';
paymentInformationCard.expirationYear = '2031';
paymentInformationCard.type = '001';
paymentInformation.card = paymentInformationCard;
requestObj.paymentInformation = paymentInformation;
var orderInformation = new cybersourceRestApi.Ptsv2paymentsidrefundsOrderInformation();
var orderInformationAmountDetails = new cybersourceRestApi.Ptsv2paymentsidcapturesOrderInformationAmountDetails();
orderInformationAmountDetails.totalAmount = '200';
orderInformationAmountDetails.currency = 'usd';
orderInformation.amountDetails = orderInformationAmountDetails;
var orderInformationBillTo = new cybersourceRestApi.Ptsv2paymentsidcapturesOrderInformationBillTo();
orderInformationBillTo.firstName = 'John';
orderInformationBillTo.lastName = 'Deo';
orderInformationBillTo.address1 = '900 Metro Center Blvd';
orderInformationBillTo.locality = 'Foster City';
orderInformationBillTo.administrativeArea = 'CA';
orderInformationBillTo.postalCode = '48104-2201';
orderInformationBillTo.country = 'US';
orderInformationBillTo.email = 'test@cybs.com';
orderInformationBillTo.phoneNumber = '9321499232';
orderInformation.billTo = orderInformationBillTo;
requestObj.orderInformation = orderInformation;
var instance = new cybersourceRestApi.CreditApi(configObject, apiClient);
instance.createCredit( 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 Credit : ' + 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) {
credit(function () {
console.log('\nCreateCredit end.');
});
}
module.exports.credit = credit;