@winible/winible-typed 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/typed-model/post.js +0 -12
- package/dist/typed-model/post.js.map +1 -1
- package/dist/typed-model/subscription-plan.js +0 -11
- package/dist/typed-model/subscription-plan.js.map +1 -1
- package/package.json +1 -1
- package/typed-model/post.ts +0 -13
- package/typed-model/subscription-plan.ts +0 -12
- package/dist/migrations/20220601151258-custom_name_describing_your_migration.js +0 -19
- package/dist/migrations/20220601151258-custom_name_describing_your_migration.js.map +0 -1
- package/dist/migrations/20220605225655-create-dashboard-user-permissions.js +0 -27
- package/dist/migrations/20220605225655-create-dashboard-user-permissions.js.map +0 -1
- package/dist/migrations/20220606001300-update-dashboard-user-permissions.js +0 -14
- package/dist/migrations/20220606001300-update-dashboard-user-permissions.js.map +0 -1
- package/dist/migrations/20220607091109-add-read-date-for-message.js +0 -19
- package/dist/migrations/20220607091109-add-read-date-for-message.js.map +0 -1
- package/dist/migrations/20220616225456-add-delete-columns.js +0 -21
- package/dist/migrations/20220616225456-add-delete-columns.js.map +0 -1
- package/dist/migrations/20220709202211-disable-feed.js +0 -24
- package/dist/migrations/20220709202211-disable-feed.js.map +0 -1
- package/dist/migrations/20220723215213-limit-promotion-claims.js +0 -18
- package/dist/migrations/20220723215213-limit-promotion-claims.js.map +0 -1
- package/dist/migrations/20220723220233-num_claims.js +0 -12
- package/dist/migrations/20220723220233-num_claims.js.map +0 -1
- package/dist/migrations/20220723221907-default_false_promos.js +0 -17
- package/dist/migrations/20220723221907-default_false_promos.js.map +0 -1
- package/dist/migrations/20220724172559-default_zero_claims.js +0 -13
- package/dist/migrations/20220724172559-default_zero_claims.js.map +0 -1
- package/dist/migrations/20220724201419-pinned_post.js +0 -13
- package/dist/migrations/20220724201419-pinned_post.js.map +0 -1
- package/dist/migrations/20220729164625-unsend_mass.js +0 -12
- package/dist/migrations/20220729164625-unsend_mass.js.map +0 -1
- package/dist/migrations/20220823033002-interval-unit.js +0 -14
- package/dist/migrations/20220823033002-interval-unit.js.map +0 -1
- package/dist/migrations/20220830193530-processorId.js +0 -15
- package/dist/migrations/20220830193530-processorId.js.map +0 -1
- package/dist/migrations/20220907121932-add-processor-to-sub.js +0 -15
- package/dist/migrations/20220907121932-add-processor-to-sub.js.map +0 -1
- package/dist/migrations/20220907212232-add-trans-id.js +0 -12
- package/dist/migrations/20220907212232-add-trans-id.js.map +0 -1
- package/dist/migrations/20220907220423-big-int-trans.js +0 -12
- package/dist/migrations/20220907220423-big-int-trans.js.map +0 -1
- package/dist/migrations/20220909161902-add-stale.js +0 -13
- package/dist/migrations/20220909161902-add-stale.js.map +0 -1
- package/dist/migrations/20220922000225-verified-spender.js +0 -13
- package/dist/migrations/20220922000225-verified-spender.js.map +0 -1
- package/dist/migrations/20220922212108-verified-spender-2.js +0 -16
- package/dist/migrations/20220922212108-verified-spender-2.js.map +0 -1
- package/dist/migrations/20221013223648-product-subscription-list.js +0 -12
- package/dist/migrations/20221013223648-product-subscription-list.js.map +0 -1
- package/dist/migrations/20221014001037-product-subscription-list.js +0 -75
- package/dist/migrations/20221014001037-product-subscription-list.js.map +0 -1
- package/dist/migrations/20221026055245-update-type.js +0 -15
- package/dist/migrations/20221026055245-update-type.js.map +0 -1
- package/dist/migrations/20221108060019-recurly-sub.js +0 -34
- package/dist/migrations/20221108060019-recurly-sub.js.map +0 -1
- package/dist/migrations/20221110170148-rename-recurly-account.js +0 -9
- package/dist/migrations/20221110170148-rename-recurly-account.js.map +0 -1
- package/dist/migrations/20221112212510-archive-promo.js +0 -13
- package/dist/migrations/20221112212510-archive-promo.js.map +0 -1
- package/dist/migrations/20221117044529-sub-status.js +0 -13
- package/dist/migrations/20221117044529-sub-status.js.map +0 -1
- package/dist/migrations/20221122051433-default-plan.js +0 -13
- package/dist/migrations/20221122051433-default-plan.js.map +0 -1
- package/dist/migrations/20221128034620-invoice-id.js +0 -12
- package/dist/migrations/20221128034620-invoice-id.js.map +0 -1
- package/dist/migrations/20230330174702-extend-premium-content.js +0 -35
- package/dist/migrations/20230330174702-extend-premium-content.js.map +0 -1
- package/dist/scripts/bet-syncing/findGoodBets.js +0 -238
- package/dist/scripts/bet-syncing/findGoodBets.js.map +0 -1
- package/dist/scripts/bet-syncing/gradeBets.js +0 -109
- package/dist/scripts/bet-syncing/gradeBets.js.map +0 -1
- package/dist/scripts/bet-syncing/pullGames.js +0 -198
- package/dist/scripts/bet-syncing/pullGames.js.map +0 -1
- package/dist/scripts/bet-syncing/pullLiveScores.js +0 -187
- package/dist/scripts/bet-syncing/pullLiveScores.js.map +0 -1
- package/dist/scripts/bet-syncing/pullOdds.js +0 -268
- package/dist/scripts/bet-syncing/pullOdds.js.map +0 -1
- package/dist/scripts/bet-syncing/pullPlayerResults.js +0 -89
- package/dist/scripts/bet-syncing/pullPlayerResults.js.map +0 -1
- package/dist/scripts/bet-syncing/pullPlayers.js +0 -59
- package/dist/scripts/bet-syncing/pullPlayers.js.map +0 -1
- package/dist/scripts/bet-syncing/pullScores.js +0 -183
- package/dist/scripts/bet-syncing/pullScores.js.map +0 -1
- package/dist/scripts/bet-syncing/pullTeams.js +0 -85
- package/dist/scripts/bet-syncing/pullTeams.js.map +0 -1
- package/dist/scripts/bet-syncing/updateStaleOdds.js +0 -34
- package/dist/scripts/bet-syncing/updateStaleOdds.js.map +0 -1
- package/dist/scripts/createDashboardLink.js +0 -30
- package/dist/scripts/createDashboardLink.js.map +0 -1
- package/dist/scripts/createRecurlyPlans.js +0 -124
- package/dist/scripts/createRecurlyPlans.js.map +0 -1
- package/dist/scripts/mapCurrentPaymentsToInvoiceId.js +0 -98
- package/dist/scripts/mapCurrentPaymentsToInvoiceId.js.map +0 -1
- package/dist/scripts/payoutRecurlySubs.js +0 -160
- package/dist/scripts/payoutRecurlySubs.js.map +0 -1
- package/dist/scripts/payoutSubscriptions.js +0 -201
- package/dist/scripts/payoutSubscriptions.js.map +0 -1
- package/dist/scripts/removeUnreferenceSubs.js +0 -39
- package/dist/scripts/removeUnreferenceSubs.js.map +0 -1
- package/dist/slack/index.js +0 -26
- package/dist/slack/index.js.map +0 -1
- package/dist/slack/v1/bypassCreator.js +0 -81
- package/dist/slack/v1/bypassCreator.js.map +0 -1
- package/dist/slack/v1/cancelSubscription.js +0 -35
- package/dist/slack/v1/cancelSubscription.js.map +0 -1
- package/dist/slack/v1/changeName.js +0 -41
- package/dist/slack/v1/changeName.js.map +0 -1
- package/dist/slack/v1/checkAuthSub.js +0 -58
- package/dist/slack/v1/checkAuthSub.js.map +0 -1
- package/dist/slack/v1/dashboardLink.js +0 -30
- package/dist/slack/v1/dashboardLink.js.map +0 -1
- package/dist/slack/v1/index.js +0 -21
- package/dist/slack/v1/index.js.map +0 -1
- package/dist/slack/v1/refund.js +0 -42
- package/dist/slack/v1/refund.js.map +0 -1
- package/dist/slack/v1/searchUser.js +0 -169
- package/dist/slack/v1/searchUser.js.map +0 -1
- package/dist/src/pk-client.js +0 -1103
- package/dist/src/pk-client.js.map +0 -1
- package/dist/src/pk-sub.js +0 -310
- package/dist/src/pk-sub.js.map +0 -1
- package/dist/typed-model/asset-category.js +0 -38
- package/dist/typed-model/asset-category.js.map +0 -1
- package/dist/typed-model/asset-constent-person.js +0 -56
- package/dist/typed-model/asset-constent-person.js.map +0 -1
- package/dist/typed-model/bet.js +0 -64
- package/dist/typed-model/bet.js.map +0 -1
- package/dist/typed-model/blocked-ip.js +0 -34
- package/dist/typed-model/blocked-ip.js.map +0 -1
- package/dist/typed-model/category-tag.js +0 -46
- package/dist/typed-model/category-tag.js.map +0 -1
- package/dist/typed-model/consent-person.js +0 -55
- package/dist/typed-model/consent-person.js.map +0 -1
- package/dist/typed-model/content-category-tag.js +0 -58
- package/dist/typed-model/content-category-tag.js.map +0 -1
- package/dist/typed-model/credit-payment.js +0 -108
- package/dist/typed-model/credit-payment.js.map +0 -1
- package/dist/typed-model/credit-payout.js +0 -42
- package/dist/typed-model/credit-payout.js.map +0 -1
- package/dist/typed-model/credit-purchase.js +0 -46
- package/dist/typed-model/credit-purchase.js.map +0 -1
- package/dist/typed-model/customer-profile.js +0 -52
- package/dist/typed-model/customer-profile.js.map +0 -1
- package/dist/typed-model/dashboard-user-permissions.js +0 -34
- package/dist/typed-model/dashboard-user-permissions.js.map +0 -1
- package/dist/typed-model/dashboard-user.js +0 -109
- package/dist/typed-model/dashboard-user.js.map +0 -1
- package/dist/typed-model/fan-list.js +0 -46
- package/dist/typed-model/fan-list.js.map +0 -1
- package/dist/typed-model/fraud.js +0 -41
- package/dist/typed-model/fraud.js.map +0 -1
- package/dist/typed-model/game.js +0 -234
- package/dist/typed-model/game.js.map +0 -1
- package/dist/typed-model/list-member.js +0 -47
- package/dist/typed-model/list-member.js.map +0 -1
- package/dist/typed-model/market.js +0 -36
- package/dist/typed-model/market.js.map +0 -1
- package/dist/typed-model/mass-message.js +0 -43
- package/dist/typed-model/mass-message.js.map +0 -1
- package/dist/typed-model/media-category.js +0 -49
- package/dist/typed-model/media-category.js.map +0 -1
- package/dist/typed-model/message-media.js +0 -53
- package/dist/typed-model/message-media.js.map +0 -1
- package/dist/typed-model/message.js +0 -191
- package/dist/typed-model/message.js.map +0 -1
- package/dist/typed-model/odds.js +0 -160
- package/dist/typed-model/odds.js.map +0 -1
- package/dist/typed-model/parlay.js +0 -30
- package/dist/typed-model/parlay.js.map +0 -1
- package/dist/typed-model/phone-chat-participation.js +0 -127
- package/dist/typed-model/phone-chat-participation.js.map +0 -1
- package/dist/typed-model/phone-chat.js +0 -118
- package/dist/typed-model/phone-chat.js.map +0 -1
- package/dist/typed-model/phone-owner.js +0 -266
- package/dist/typed-model/phone-owner.js.map +0 -1
- package/dist/typed-model/phone-user.js +0 -109
- package/dist/typed-model/phone-user.js.map +0 -1
- package/dist/typed-model/player-result.js +0 -67
- package/dist/typed-model/player-result.js.map +0 -1
- package/dist/typed-model/player.js +0 -87
- package/dist/typed-model/player.js.map +0 -1
- package/dist/typed-model/premium-content.js +0 -128
- package/dist/typed-model/premium-content.js.map +0 -1
- package/dist/typed-model/purchased-content.js +0 -69
- package/dist/typed-model/purchased-content.js.map +0 -1
- package/dist/typed-model/short-url.js +0 -88
- package/dist/typed-model/short-url.js.map +0 -1
- package/dist/typed-model/sportsbook.js +0 -31
- package/dist/typed-model/sportsbook.js.map +0 -1
- package/dist/typed-model/subscription-bundle.js +0 -57
- package/dist/typed-model/subscription-bundle.js.map +0 -1
- package/dist/typed-model/subscription-category-tags.js +0 -58
- package/dist/typed-model/subscription-category-tags.js.map +0 -1
- package/dist/typed-model/subscription-plan-on-premium-content.js +0 -57
- package/dist/typed-model/subscription-plan-on-premium-content.js.map +0 -1
- package/dist/typed-model/subscription-promotion.js +0 -101
- package/dist/typed-model/subscription-promotion.js.map +0 -1
- package/dist/typed-model/subscription.js +0 -111
- package/dist/typed-model/subscription.js.map +0 -1
- package/dist/typed-model/team.js +0 -70
- package/dist/typed-model/team.js.map +0 -1
- package/dist/typed-model/twilio-phone.js +0 -92
- package/dist/typed-model/twilio-phone.js.map +0 -1
- package/dist/typed-model/user-follow.js +0 -103
- package/dist/typed-model/user-follow.js.map +0 -1
- package/dist/typed-model/verification-code.js +0 -52
- package/dist/typed-model/verification-code.js.map +0 -1
package/dist/src/pk-client.js
DELETED
@@ -1,1103 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
-
}) : function(o, v) {
|
16
|
-
o["default"] = v;
|
17
|
-
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
-
if (mod && mod.__esModule) return mod;
|
20
|
-
var result = {};
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
-
__setModuleDefault(result, mod);
|
23
|
-
return result;
|
24
|
-
};
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
exports.getTransactionStatus = exports.refundTransaction = exports.getTransactionsForCustomerProfile = exports.updateUserPaymentProfile = exports.voidTransaction = exports.getSubscriptionList = exports.getSubscriptionStatus = exports.getSubscription = exports.updateSubscription = exports.cancelSubscription = exports.createSubscriptionWithCreditCard = exports.createSubscription = exports.chargeCustomerByPaymentProfile = exports.purchaseCreditsWithCustomerProfile = exports.purchaseCreditsWithCreditCardAndCreatorProfile = exports.chargeCreditCardAndCreateProfile = exports.updateCustomerProfile = exports.deleteCustomerProfile = exports.addPaymentProfile = exports.getCustomerPaymentProfile = exports.getCustomerProfile = exports.createCustomerProfile = void 0;
|
27
|
-
const customer_profile_1 = __importStar(require("../typed-model/customer-profile"));
|
28
|
-
const authorizenet_1 = require("authorizenet");
|
29
|
-
const moment = require("moment");
|
30
|
-
const typed_model_1 = require("../typed-model");
|
31
|
-
const mode = authorizenet_1.APIContracts.ValidationModeEnum.LIVEMODE;
|
32
|
-
const DEFAULT_PROCESSOR = customer_profile_1.ProcessorId.KAJA;
|
33
|
-
const getCredentialsForProcessorId = (processorId) => {
|
34
|
-
let apiKey = process.env.PK_API_LOGIN_KEY;
|
35
|
-
let transactionKey = process.env.PK_TRANSACTION_KEY;
|
36
|
-
switch (processorId) {
|
37
|
-
case customer_profile_1.ProcessorId.HUMBOLDT:
|
38
|
-
apiKey = process.env.PK_API_LOGIN_KEY;
|
39
|
-
transactionKey = process.env.PK_TRANSACTION_KEY;
|
40
|
-
break;
|
41
|
-
case customer_profile_1.ProcessorId.KAJA:
|
42
|
-
apiKey = process.env.KAJA_API_LOGIN_KEY;
|
43
|
-
transactionKey = process.env.KAJA_TRANSACTION_KEY;
|
44
|
-
break;
|
45
|
-
case customer_profile_1.ProcessorId.KAJACOACHING:
|
46
|
-
apiKey = process.env.KAJACOACHING_API_LOGIN_KEY;
|
47
|
-
transactionKey = process.env.KAJACOACHING_TRANSACTION_KEY;
|
48
|
-
break;
|
49
|
-
}
|
50
|
-
return {
|
51
|
-
apiKey,
|
52
|
-
transactionKey,
|
53
|
-
};
|
54
|
-
};
|
55
|
-
const getMerchantAuthForCustomer = async (customerProfileId) => {
|
56
|
-
let processorId = customer_profile_1.ProcessorId.HUMBOLDT;
|
57
|
-
let customerProfile = await typed_model_1.CustomerProfile.findOne({
|
58
|
-
where: { customerProfileId },
|
59
|
-
});
|
60
|
-
if (customerProfile) {
|
61
|
-
processorId = customerProfile.processorId;
|
62
|
-
}
|
63
|
-
return getMerchantAuthForProcessor(processorId);
|
64
|
-
};
|
65
|
-
const getMerchantAuthForProcessor = (processorId) => {
|
66
|
-
const response = getCredentialsForProcessorId(processorId);
|
67
|
-
const apiKey = response.apiKey;
|
68
|
-
const transactionKey = response.transactionKey;
|
69
|
-
const merchantAuthenticationType = new authorizenet_1.APIContracts.MerchantAuthenticationType();
|
70
|
-
merchantAuthenticationType.setName(apiKey);
|
71
|
-
merchantAuthenticationType.setTransactionKey(transactionKey);
|
72
|
-
return {
|
73
|
-
merchantAuthenticationType,
|
74
|
-
processorId,
|
75
|
-
};
|
76
|
-
};
|
77
|
-
const buildCreditCard = (card) => {
|
78
|
-
let creditCard = new authorizenet_1.APIContracts.CreditCardType();
|
79
|
-
creditCard.setCardNumber(card.cardNumber);
|
80
|
-
creditCard.setExpirationDate(card.expirationDate);
|
81
|
-
creditCard.setCardCode(card.cardCode);
|
82
|
-
return creditCard;
|
83
|
-
};
|
84
|
-
const buildAddress = (address) => {
|
85
|
-
let customerAddress = new authorizenet_1.APIContracts.CustomerAddressType();
|
86
|
-
customerAddress.setFirstName(address.firstName);
|
87
|
-
customerAddress.setLastName(address.lastName);
|
88
|
-
customerAddress.setAddress(address.address);
|
89
|
-
customerAddress.setCity(address.city);
|
90
|
-
customerAddress.setState(address.state);
|
91
|
-
customerAddress.setZip(address.zip);
|
92
|
-
customerAddress.setCountry(address.country);
|
93
|
-
return customerAddress;
|
94
|
-
};
|
95
|
-
const createCustomerProfile = async (user, data) => {
|
96
|
-
console.log("createCustomerProfile");
|
97
|
-
let { merchantAuthenticationType, processorId } = await getMerchantAuthForProcessor(DEFAULT_PROCESSOR);
|
98
|
-
let creditCard = buildCreditCard(data.payment.creditCard);
|
99
|
-
let paymentType = new authorizenet_1.APIContracts.PaymentType();
|
100
|
-
paymentType.setCreditCard(creditCard);
|
101
|
-
let customerPaymentProfileType = new authorizenet_1.APIContracts.CustomerPaymentProfileType();
|
102
|
-
customerPaymentProfileType.setCustomerType(authorizenet_1.APIContracts.CustomerTypeEnum.INDIVIDUAL);
|
103
|
-
customerPaymentProfileType.setPayment(paymentType);
|
104
|
-
customerPaymentProfileType.setDefaultPaymentProfile(true);
|
105
|
-
if (data.billTo) {
|
106
|
-
let customerAddress = buildAddress(data.billTo);
|
107
|
-
customerPaymentProfileType.setBillTo(customerAddress);
|
108
|
-
}
|
109
|
-
let paymentProfilesList = [customerPaymentProfileType];
|
110
|
-
let customerProfileType = new authorizenet_1.APIContracts.CustomerProfileType();
|
111
|
-
customerProfileType.setMerchantCustomerId(user.id);
|
112
|
-
customerProfileType.setEmail(user.email);
|
113
|
-
customerProfileType.setPaymentProfiles(paymentProfilesList);
|
114
|
-
let createRequest = new authorizenet_1.APIContracts.CreateCustomerProfileRequest();
|
115
|
-
createRequest.setProfile(customerProfileType);
|
116
|
-
createRequest.setValidationMode(mode);
|
117
|
-
createRequest.setMerchantAuthentication(merchantAuthenticationType);
|
118
|
-
//pretty print request
|
119
|
-
console.log(JSON.stringify(createRequest.getJSON(), null, 2));
|
120
|
-
let ctrl = new authorizenet_1.APIControllers.CreateCustomerProfileController(createRequest.getJSON());
|
121
|
-
if (process.env.ENVIRONMENT === "production") {
|
122
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
123
|
-
}
|
124
|
-
return new Promise((resolve, reject) => {
|
125
|
-
ctrl.execute(function () {
|
126
|
-
let apiResponse = ctrl.getResponse();
|
127
|
-
let response = new authorizenet_1.APIContracts.CreateCustomerProfileResponse(apiResponse);
|
128
|
-
//pretty print response
|
129
|
-
console.log(JSON.stringify(response, null, 2));
|
130
|
-
if (response != null) {
|
131
|
-
if (response.getMessages().getResultCode() ==
|
132
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
133
|
-
customer_profile_1.default.create({
|
134
|
-
userId: user.id,
|
135
|
-
customerProfileId: response.getCustomerProfileId(),
|
136
|
-
processorId,
|
137
|
-
}).then(() => resolve([
|
138
|
-
response.getCustomerProfileId(),
|
139
|
-
response.getCustomerPaymentProfileIdList()[0],
|
140
|
-
]));
|
141
|
-
}
|
142
|
-
else {
|
143
|
-
reject(response.getMessages().getMessage()[0].getText());
|
144
|
-
}
|
145
|
-
}
|
146
|
-
else {
|
147
|
-
reject("Null response received");
|
148
|
-
}
|
149
|
-
});
|
150
|
-
});
|
151
|
-
};
|
152
|
-
exports.createCustomerProfile = createCustomerProfile;
|
153
|
-
const getCustomerProfile = async (customerProfileId, userId) => {
|
154
|
-
let { merchantAuthenticationType, processorId } = await getMerchantAuthForCustomer(customerProfileId);
|
155
|
-
let getRequest = new authorizenet_1.APIContracts.GetCustomerProfileRequest();
|
156
|
-
getRequest.setMerchantAuthentication(merchantAuthenticationType);
|
157
|
-
if (userId) {
|
158
|
-
getRequest.setMerchantCustomerId(userId);
|
159
|
-
}
|
160
|
-
else {
|
161
|
-
getRequest.setCustomerProfileId(customerProfileId);
|
162
|
-
}
|
163
|
-
//pretty print request
|
164
|
-
// console.log(JSON.stringify(getRequest.getJSON(), null, 2));
|
165
|
-
let ctrl = new authorizenet_1.APIControllers.GetCustomerProfileController(getRequest.getJSON());
|
166
|
-
if (process.env.ENVIRONMENT === "production") {
|
167
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
168
|
-
}
|
169
|
-
return new Promise((resolve, reject) => {
|
170
|
-
ctrl.execute(function () {
|
171
|
-
let apiResponse = ctrl.getResponse();
|
172
|
-
let response = new authorizenet_1.APIContracts.GetCustomerProfileResponse(apiResponse);
|
173
|
-
//pretty print response
|
174
|
-
if (response != null) {
|
175
|
-
if (response.getMessages().getResultCode() ==
|
176
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
177
|
-
resolve(response.getProfile());
|
178
|
-
}
|
179
|
-
else {
|
180
|
-
reject(response.getMessages().getMessage()[0].getText());
|
181
|
-
}
|
182
|
-
}
|
183
|
-
else {
|
184
|
-
reject("Null response received");
|
185
|
-
}
|
186
|
-
});
|
187
|
-
});
|
188
|
-
};
|
189
|
-
exports.getCustomerProfile = getCustomerProfile;
|
190
|
-
const getCustomerPaymentProfile = async (customerProfileId, customerPaymentProfileId) => {
|
191
|
-
let { merchantAuthenticationType, processorId } = await getMerchantAuthForCustomer(customerProfileId);
|
192
|
-
let getRequest = new authorizenet_1.APIContracts.GetCustomerPaymentProfileRequest();
|
193
|
-
getRequest.setMerchantAuthentication(merchantAuthenticationType);
|
194
|
-
getRequest.setCustomerProfileId(customerProfileId);
|
195
|
-
getRequest.setCustomerPaymentProfileId(customerPaymentProfileId);
|
196
|
-
//pretty print request
|
197
|
-
//console.log(JSON.stringify(createRequest.getJSON(), null, 2));
|
198
|
-
let ctrl = new authorizenet_1.APIControllers.GetCustomerProfileController(getRequest.getJSON());
|
199
|
-
if (process.env.ENVIRONMENT === "production") {
|
200
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
201
|
-
}
|
202
|
-
return new Promise((resolve, reject) => {
|
203
|
-
ctrl.execute(function () {
|
204
|
-
let apiResponse = ctrl.getResponse();
|
205
|
-
let response = new authorizenet_1.APIContracts.GetCustomerPaymentProfileResponse(apiResponse);
|
206
|
-
//pretty print response
|
207
|
-
//console.log(JSON.stringify(response, null, 2));
|
208
|
-
if (response != null) {
|
209
|
-
if (response.getMessages().getResultCode() ==
|
210
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
211
|
-
resolve(response.getPaymentProfile());
|
212
|
-
}
|
213
|
-
else {
|
214
|
-
reject(response.getMessages().getMessage()[0].getText());
|
215
|
-
}
|
216
|
-
}
|
217
|
-
else {
|
218
|
-
reject("Get payment profile Null response received");
|
219
|
-
}
|
220
|
-
});
|
221
|
-
});
|
222
|
-
};
|
223
|
-
exports.getCustomerPaymentProfile = getCustomerPaymentProfile;
|
224
|
-
const addPaymentProfile = async (customerProfileId, data) => {
|
225
|
-
let { merchantAuthenticationType, processorId } = await getMerchantAuthForCustomer(customerProfileId);
|
226
|
-
let creditCard = buildCreditCard(data.payment.creditCard);
|
227
|
-
let paymentType = new authorizenet_1.APIContracts.PaymentType();
|
228
|
-
paymentType.setCreditCard(creditCard);
|
229
|
-
let customerAddress = buildAddress(data.billTo);
|
230
|
-
let profile = new authorizenet_1.APIContracts.CustomerPaymentProfileType();
|
231
|
-
profile.setBillTo(customerAddress);
|
232
|
-
profile.setPayment(paymentType);
|
233
|
-
profile.setDefaultPaymentProfile(data.defaultPaymentProfile || false);
|
234
|
-
let createRequest = new authorizenet_1.APIContracts.CreateCustomerPaymentProfileRequest();
|
235
|
-
createRequest.setMerchantAuthentication(merchantAuthenticationType);
|
236
|
-
createRequest.setCustomerProfileId(customerProfileId);
|
237
|
-
createRequest.setPaymentProfile(profile);
|
238
|
-
//pretty print request
|
239
|
-
// console.log(JSON.stringify(createRequest.getJSON(), null, 2));
|
240
|
-
let ctrl = new authorizenet_1.APIControllers.CreateCustomerPaymentProfileController(createRequest.getJSON());
|
241
|
-
if (process.env.ENVIRONMENT === "production") {
|
242
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
243
|
-
}
|
244
|
-
return new Promise((resolve, reject) => {
|
245
|
-
ctrl.execute(function () {
|
246
|
-
let apiResponse = ctrl.getResponse();
|
247
|
-
let response = new authorizenet_1.APIContracts.CreateCustomerPaymentProfileResponse(apiResponse);
|
248
|
-
//pretty print response
|
249
|
-
console.log(JSON.stringify(response, null, 2));
|
250
|
-
if (response != null) {
|
251
|
-
if (response.getMessages().getResultCode() ==
|
252
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
253
|
-
resolve(response.getCustomerPaymentProfileId());
|
254
|
-
}
|
255
|
-
else {
|
256
|
-
reject(response.getMessages().getMessage()[0].getText());
|
257
|
-
}
|
258
|
-
}
|
259
|
-
else {
|
260
|
-
reject("Null response received");
|
261
|
-
}
|
262
|
-
});
|
263
|
-
});
|
264
|
-
};
|
265
|
-
exports.addPaymentProfile = addPaymentProfile;
|
266
|
-
const deleteCustomerProfile = async (customerProfileId, customerPaymentProfileId) => {
|
267
|
-
let { merchantAuthenticationType, processorId } = await getMerchantAuthForCustomer(customerProfileId);
|
268
|
-
let deleteRequest = new authorizenet_1.APIContracts.DeleteCustomerPaymentProfileRequest();
|
269
|
-
deleteRequest.setMerchantAuthentication(merchantAuthenticationType);
|
270
|
-
deleteRequest.setCustomerProfileId(customerProfileId);
|
271
|
-
deleteRequest.setCustomerPaymentProfileId(customerPaymentProfileId);
|
272
|
-
//pretty print request
|
273
|
-
//console.log(JSON.stringify(createRequest.getJSON(), null, 2));
|
274
|
-
let ctrl = new authorizenet_1.APIControllers.DeleteCustomerPaymentProfileController(deleteRequest.getJSON());
|
275
|
-
if (process.env.ENVIRONMENT === "production") {
|
276
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
277
|
-
}
|
278
|
-
return new Promise((resolve, reject) => {
|
279
|
-
ctrl.execute(function () {
|
280
|
-
let apiResponse = ctrl.getResponse();
|
281
|
-
let response = new authorizenet_1.APIContracts.DeleteCustomerPaymentProfileResponse(apiResponse);
|
282
|
-
if (response != null) {
|
283
|
-
if (response.getMessages().getResultCode() ==
|
284
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
285
|
-
resolve(customerPaymentProfileId);
|
286
|
-
}
|
287
|
-
else {
|
288
|
-
reject(response.getMessages().getMessage()[0].getText());
|
289
|
-
}
|
290
|
-
}
|
291
|
-
else {
|
292
|
-
reject("Null response received");
|
293
|
-
}
|
294
|
-
});
|
295
|
-
});
|
296
|
-
};
|
297
|
-
exports.deleteCustomerProfile = deleteCustomerProfile;
|
298
|
-
const updateCustomerProfile = async (customerProfileId, customerPaymentProfileId, data) => {
|
299
|
-
let { merchantAuthenticationType, processorId } = await getMerchantAuthForCustomer(customerProfileId);
|
300
|
-
let oldProfile = await (0, exports.getCustomerPaymentProfile)(customerProfileId, customerPaymentProfileId);
|
301
|
-
console.log(oldProfile);
|
302
|
-
if (!oldProfile) {
|
303
|
-
throw Error("No payment profile found");
|
304
|
-
}
|
305
|
-
let creditCardForUpdate = buildCreditCard((data.payment && data.payment.creditCard) || oldProfile.payment.creditCard);
|
306
|
-
let paymentType = new authorizenet_1.APIContracts.PaymentType();
|
307
|
-
paymentType.setCreditCard(creditCardForUpdate);
|
308
|
-
let customerAddressType = buildAddress(data.billTo || oldProfile.billTo);
|
309
|
-
let customerForUpdate = new authorizenet_1.APIContracts.CustomerPaymentProfileExType();
|
310
|
-
customerForUpdate.setPayment(paymentType);
|
311
|
-
//customerForUpdate.setDefaultPaymentProfile(true);
|
312
|
-
customerForUpdate.setDefaultPaymentProfile(data.defaultPaymentProfile || false);
|
313
|
-
customerForUpdate.setCustomerPaymentProfileId(customerPaymentProfileId);
|
314
|
-
customerForUpdate.setBillTo(customerAddressType);
|
315
|
-
let updateRequest = new authorizenet_1.APIContracts.UpdateCustomerPaymentProfileRequest();
|
316
|
-
updateRequest.setMerchantAuthentication(merchantAuthenticationType);
|
317
|
-
updateRequest.setCustomerProfileId(customerProfileId);
|
318
|
-
updateRequest.setPaymentProfile(customerForUpdate);
|
319
|
-
updateRequest.setValidationMode(mode);
|
320
|
-
let ctrl = new authorizenet_1.APIControllers.UpdateCustomerPaymentProfileController(updateRequest.getJSON());
|
321
|
-
if (process.env.ENVIRONMENT === "production") {
|
322
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
323
|
-
}
|
324
|
-
return new Promise((resolve, reject) => {
|
325
|
-
ctrl.execute(function () {
|
326
|
-
let apiResponse = ctrl.getResponse();
|
327
|
-
let response = new authorizenet_1.APIContracts.UpdateCustomerPaymentProfileResponse(apiResponse);
|
328
|
-
if (response != null) {
|
329
|
-
if (response.getMessages().getResultCode() ==
|
330
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
331
|
-
console.log("Successfully updated a customer payment profile with id: " +
|
332
|
-
customerPaymentProfileId);
|
333
|
-
resolve({ customerPaymentProfileId, processorId });
|
334
|
-
}
|
335
|
-
else {
|
336
|
-
reject(response.getMessages().getMessage()[0].getText());
|
337
|
-
}
|
338
|
-
}
|
339
|
-
else {
|
340
|
-
reject("Null response received");
|
341
|
-
}
|
342
|
-
});
|
343
|
-
});
|
344
|
-
};
|
345
|
-
exports.updateCustomerProfile = updateCustomerProfile;
|
346
|
-
const chargeCreditCardAndCreateProfile = async (user, data, amountInCents, description, skipProfileCreation, useCoachingMid) => {
|
347
|
-
let { merchantAuthenticationType, processorId } = await getMerchantAuthForProcessor(useCoachingMid ? DEFAULT_PROCESSOR : DEFAULT_PROCESSOR);
|
348
|
-
let creditCard = buildCreditCard(data.payment.creditCard);
|
349
|
-
let paymentType = new authorizenet_1.APIContracts.PaymentType();
|
350
|
-
paymentType.setCreditCard(creditCard);
|
351
|
-
let customerAddress = buildAddress(data.billTo);
|
352
|
-
var userField = new authorizenet_1.APIContracts.UserField();
|
353
|
-
userField.setName("userId");
|
354
|
-
userField.setValue(user.id);
|
355
|
-
var userFields = new authorizenet_1.APIContracts.TransactionRequestType.UserFields();
|
356
|
-
var ufArray = [userField];
|
357
|
-
userFields.setUserField(ufArray);
|
358
|
-
var transactionSetting1 = new authorizenet_1.APIContracts.SettingType();
|
359
|
-
transactionSetting1.setSettingName("duplicateWindow");
|
360
|
-
transactionSetting1.setSettingValue("5");
|
361
|
-
var transactionSetting2 = new authorizenet_1.APIContracts.SettingType();
|
362
|
-
transactionSetting2.setSettingName("recurringBilling");
|
363
|
-
transactionSetting2.setSettingValue("false");
|
364
|
-
var transactionSettingList = [transactionSetting1, transactionSetting2];
|
365
|
-
var transactionSettings = new authorizenet_1.APIContracts.ArrayOfSetting();
|
366
|
-
transactionSettings.setSetting(transactionSettingList);
|
367
|
-
var profile = new authorizenet_1.APIContracts.CustomerProfilePaymentType();
|
368
|
-
profile.setCreateProfile(skipProfileCreation ? false : true);
|
369
|
-
let customerProfileType = new authorizenet_1.APIContracts.CustomerType();
|
370
|
-
customerProfileType.setId(user.id);
|
371
|
-
customerProfileType.setEmail(user.email);
|
372
|
-
customerProfileType.setType(authorizenet_1.APIContracts.CustomerTypeEnum.INDIVIDUAL);
|
373
|
-
// let customerBaseType = new APIContracts.CustomerPaymentProfileBaseType();
|
374
|
-
// customerBaseType.setCustomerType(customerProfileType);
|
375
|
-
// customerBaseType.setBillTo(customerAddress);
|
376
|
-
var orderDetails = new authorizenet_1.APIContracts.OrderType();
|
377
|
-
orderDetails.setDescription(description);
|
378
|
-
var transactionRequestType = new authorizenet_1.APIContracts.TransactionRequestType();
|
379
|
-
transactionRequestType.setTransactionType(authorizenet_1.APIContracts.TransactionTypeEnum.AUTHCAPTURETRANSACTION);
|
380
|
-
transactionRequestType.setPayment(paymentType);
|
381
|
-
transactionRequestType.setAmount(amountInCents / 100.0);
|
382
|
-
transactionRequestType.setUserFields(userFields);
|
383
|
-
transactionRequestType.setOrder(orderDetails);
|
384
|
-
transactionRequestType.setBillTo(customerAddress);
|
385
|
-
transactionRequestType.setTransactionSettings(transactionSettings);
|
386
|
-
transactionRequestType.setProfile(profile);
|
387
|
-
transactionRequestType.setCustomer(customerProfileType);
|
388
|
-
var createRequest = new authorizenet_1.APIContracts.CreateTransactionRequest();
|
389
|
-
createRequest.setMerchantAuthentication(merchantAuthenticationType);
|
390
|
-
createRequest.setTransactionRequest(transactionRequestType);
|
391
|
-
var ctrl = new authorizenet_1.APIControllers.CreateTransactionController(createRequest.getJSON());
|
392
|
-
if (process.env.ENVIRONMENT === "production") {
|
393
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
394
|
-
}
|
395
|
-
return new Promise((resolve, reject) => {
|
396
|
-
ctrl.execute(function () {
|
397
|
-
let apiResponse = ctrl.getResponse();
|
398
|
-
let response = new authorizenet_1.APIContracts.CreateTransactionResponse(apiResponse);
|
399
|
-
//pretty print response
|
400
|
-
console.log(JSON.stringify(response, null, 2));
|
401
|
-
if (response != null) {
|
402
|
-
let transactionResponse = response.getTransactionResponse();
|
403
|
-
let profileResponse = response.getProfileResponse();
|
404
|
-
if (response.getMessages().getResultCode() ==
|
405
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
406
|
-
if (transactionResponse.getMessages() != null) {
|
407
|
-
return resolve({
|
408
|
-
amountInCents,
|
409
|
-
transactionId: transactionResponse.getTransId(),
|
410
|
-
pkCustomerProfileId: profileResponse && profileResponse.getCustomerProfileId(),
|
411
|
-
pkCustomerPaymentProfileId: profileResponse &&
|
412
|
-
profileResponse.getCustomerPaymentProfileIdList() &&
|
413
|
-
profileResponse
|
414
|
-
.getCustomerPaymentProfileIdList()
|
415
|
-
.getNumericString()[0]
|
416
|
-
.toString(),
|
417
|
-
processorId,
|
418
|
-
});
|
419
|
-
}
|
420
|
-
else {
|
421
|
-
if (transactionResponse.getErrors() != null) {
|
422
|
-
return reject(transactionResponse.getErrors().getError()[0].getErrorText());
|
423
|
-
}
|
424
|
-
}
|
425
|
-
}
|
426
|
-
else {
|
427
|
-
console.log("Failed Transaction. ");
|
428
|
-
if (transactionResponse != null &&
|
429
|
-
transactionResponse.getErrors() != null) {
|
430
|
-
return reject(transactionResponse.getErrors().getError()[0].getErrorText());
|
431
|
-
}
|
432
|
-
else {
|
433
|
-
return reject(response.getMessages().getMessage()[0].getText());
|
434
|
-
}
|
435
|
-
}
|
436
|
-
}
|
437
|
-
else {
|
438
|
-
reject("Null response received");
|
439
|
-
}
|
440
|
-
});
|
441
|
-
});
|
442
|
-
};
|
443
|
-
exports.chargeCreditCardAndCreateProfile = chargeCreditCardAndCreateProfile;
|
444
|
-
const purchaseCreditsWithCreditCardAndCreatorProfile = async (user, data, amountInCents) => {
|
445
|
-
let chargeResponse = await (0, exports.chargeCreditCardAndCreateProfile)(user, data, amountInCents, "CLIQ Credits");
|
446
|
-
if (chargeResponse.pkCustomerProfileId &&
|
447
|
-
chargeResponse.pkCustomerPaymentProfileId) {
|
448
|
-
await (0, exports.updateUserPaymentProfile)(user.id, chargeResponse.pkCustomerProfileId, chargeResponse.processorId, chargeResponse.pkCustomerPaymentProfileId);
|
449
|
-
}
|
450
|
-
return {
|
451
|
-
amountInCents: chargeResponse.amountInCents,
|
452
|
-
transactionId: chargeResponse.transactionId,
|
453
|
-
processorId: chargeResponse.processorId,
|
454
|
-
};
|
455
|
-
};
|
456
|
-
exports.purchaseCreditsWithCreditCardAndCreatorProfile = purchaseCreditsWithCreditCardAndCreatorProfile;
|
457
|
-
const purchaseCreditsWithCustomerProfile = async (customerProfileId, customerPaymentProfileId, amountInCents) => {
|
458
|
-
return await (0, exports.chargeCustomerByPaymentProfile)(customerProfileId, customerPaymentProfileId, amountInCents, "CLIQ Credits");
|
459
|
-
};
|
460
|
-
exports.purchaseCreditsWithCustomerProfile = purchaseCreditsWithCustomerProfile;
|
461
|
-
const chargeCustomerByPaymentProfile = async (customerProfileId, customerPaymentProfileId, amountInCents, description) => {
|
462
|
-
let { merchantAuthenticationType, processorId } = await getMerchantAuthForCustomer(customerProfileId);
|
463
|
-
var profileToCharge = new authorizenet_1.APIContracts.CustomerProfilePaymentType();
|
464
|
-
profileToCharge.setCustomerProfileId(customerProfileId);
|
465
|
-
var paymentProfile = new authorizenet_1.APIContracts.PaymentProfile();
|
466
|
-
paymentProfile.setPaymentProfileId(customerPaymentProfileId);
|
467
|
-
profileToCharge.setPaymentProfile(paymentProfile);
|
468
|
-
var orderDetails = new authorizenet_1.APIContracts.OrderType();
|
469
|
-
orderDetails.setDescription(description);
|
470
|
-
var duplicateWindow = new authorizenet_1.APIContracts.SettingType();
|
471
|
-
duplicateWindow.setSettingName("duplicateWindow");
|
472
|
-
duplicateWindow.setSettingValue("5");
|
473
|
-
var transactionSettingList = [];
|
474
|
-
transactionSettingList.push(duplicateWindow);
|
475
|
-
var transactionSettings = new authorizenet_1.APIContracts.ArrayOfSetting();
|
476
|
-
transactionSettings.setSetting(transactionSettingList);
|
477
|
-
var transactionRequestType = new authorizenet_1.APIContracts.TransactionRequestType();
|
478
|
-
transactionRequestType.setTransactionType(authorizenet_1.APIContracts.TransactionTypeEnum.AUTHCAPTURETRANSACTION);
|
479
|
-
transactionRequestType.setProfile(profileToCharge);
|
480
|
-
transactionRequestType.setAmount(amountInCents / 100.0);
|
481
|
-
transactionRequestType.setTransactionSettings(transactionSettings);
|
482
|
-
transactionRequestType.setOrder(orderDetails);
|
483
|
-
var createRequest = new authorizenet_1.APIContracts.CreateTransactionRequest();
|
484
|
-
createRequest.setMerchantAuthentication(merchantAuthenticationType);
|
485
|
-
createRequest.setTransactionRequest(transactionRequestType);
|
486
|
-
var ctrl = new authorizenet_1.APIControllers.CreateTransactionController(createRequest.getJSON());
|
487
|
-
if (process.env.ENVIRONMENT === "production") {
|
488
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
489
|
-
}
|
490
|
-
return new Promise((resolve, reject) => {
|
491
|
-
ctrl.execute(function () {
|
492
|
-
var apiResponse = ctrl.getResponse();
|
493
|
-
var response = new authorizenet_1.APIContracts.CreateTransactionResponse(apiResponse);
|
494
|
-
//pretty print response
|
495
|
-
console.log(JSON.stringify(response, null, 2));
|
496
|
-
if (response != null) {
|
497
|
-
if (response.getMessages().getResultCode() ==
|
498
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
499
|
-
if (response.getTransactionResponse().getMessages() != null) {
|
500
|
-
// Success
|
501
|
-
console.log("Successful transaction");
|
502
|
-
resolve({
|
503
|
-
transactionId: response.getTransactionResponse().getTransId(),
|
504
|
-
amountInCents,
|
505
|
-
processorId,
|
506
|
-
});
|
507
|
-
}
|
508
|
-
else {
|
509
|
-
console.log("Failed Transaction.");
|
510
|
-
if (response.getTransactionResponse().getErrors() != null) {
|
511
|
-
reject(response
|
512
|
-
.getTransactionResponse()
|
513
|
-
.getErrors()
|
514
|
-
.getError()[0]
|
515
|
-
.getErrorText());
|
516
|
-
}
|
517
|
-
else {
|
518
|
-
reject("Failed Transaction.");
|
519
|
-
}
|
520
|
-
}
|
521
|
-
}
|
522
|
-
else {
|
523
|
-
if (response.getTransactionResponse() != null &&
|
524
|
-
response.getTransactionResponse().getErrors() != null) {
|
525
|
-
reject(response
|
526
|
-
.getTransactionResponse()
|
527
|
-
.getErrors()
|
528
|
-
.getError()[0]
|
529
|
-
.getErrorText());
|
530
|
-
}
|
531
|
-
else {
|
532
|
-
reject(response.getMessages().getMessage()[0].getText());
|
533
|
-
}
|
534
|
-
}
|
535
|
-
}
|
536
|
-
else {
|
537
|
-
reject("Null Response.");
|
538
|
-
}
|
539
|
-
});
|
540
|
-
});
|
541
|
-
};
|
542
|
-
exports.chargeCustomerByPaymentProfile = chargeCustomerByPaymentProfile;
|
543
|
-
async function createSubscription({ intervalCount, intervalUnit, trialLength, amountInCents, trialAmountInCents, customerProfileId, customerPaymentProfileId, creatorName, processorId, startDate, }) {
|
544
|
-
try {
|
545
|
-
let { merchantAuthenticationType } = await getMerchantAuthForProcessor(processorId);
|
546
|
-
return new Promise(async (resolve, reject) => {
|
547
|
-
var interval = new authorizenet_1.APIContracts.PaymentScheduleType.Interval();
|
548
|
-
interval.setLength(intervalCount);
|
549
|
-
interval.setUnit(intervalUnit);
|
550
|
-
var paymentScheduleType = new authorizenet_1.APIContracts.PaymentScheduleType();
|
551
|
-
paymentScheduleType.setInterval(interval);
|
552
|
-
paymentScheduleType.setStartDate(moment(startDate)
|
553
|
-
.add(intervalCount, intervalUnit)
|
554
|
-
.add(1, "day")
|
555
|
-
.toISOString()
|
556
|
-
.substring(0, 10));
|
557
|
-
paymentScheduleType.setTotalOccurrences(9999);
|
558
|
-
paymentScheduleType.setTrialOccurrences(trialLength);
|
559
|
-
var customerProfileIdType = new authorizenet_1.APIContracts.CustomerProfileIdType();
|
560
|
-
customerProfileIdType.setCustomerProfileId(customerProfileId);
|
561
|
-
customerProfileIdType.setCustomerPaymentProfileId(customerPaymentProfileId);
|
562
|
-
var arbSubscription = new authorizenet_1.APIContracts.ARBSubscriptionType();
|
563
|
-
arbSubscription.setName(`${creatorName} ${intervalUnit == "days" ? "weekly" : "monthly"} subscription`);
|
564
|
-
arbSubscription.setPaymentSchedule(paymentScheduleType);
|
565
|
-
arbSubscription.setAmount(amountInCents / 100.0);
|
566
|
-
arbSubscription.setTrialAmount((trialAmountInCents || 0) / 100.0);
|
567
|
-
arbSubscription.setProfile(customerProfileIdType);
|
568
|
-
var createRequest = new authorizenet_1.APIContracts.ARBCreateSubscriptionRequest();
|
569
|
-
createRequest.setMerchantAuthentication(merchantAuthenticationType);
|
570
|
-
createRequest.setSubscription(arbSubscription);
|
571
|
-
var ctrl = new authorizenet_1.APIControllers.ARBCreateSubscriptionController(createRequest.getJSON());
|
572
|
-
if (process.env.ENVIRONMENT === "production") {
|
573
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
574
|
-
}
|
575
|
-
ctrl.execute(function () {
|
576
|
-
var apiResponse = ctrl.getResponse();
|
577
|
-
var response = new authorizenet_1.APIContracts.ARBCreateSubscriptionResponse(apiResponse);
|
578
|
-
console.log(JSON.stringify(response, null, 2));
|
579
|
-
if (response != null) {
|
580
|
-
if (response.getMessages().getResultCode() ==
|
581
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
582
|
-
resolve({ pkSubId: response.getSubscriptionId() });
|
583
|
-
}
|
584
|
-
else {
|
585
|
-
reject(response.getMessages().getMessage()[0].getText());
|
586
|
-
}
|
587
|
-
}
|
588
|
-
else {
|
589
|
-
reject("Null Response.");
|
590
|
-
}
|
591
|
-
});
|
592
|
-
});
|
593
|
-
}
|
594
|
-
catch (err) {
|
595
|
-
console.log(err);
|
596
|
-
throw new Error("Subscription failed to create");
|
597
|
-
}
|
598
|
-
}
|
599
|
-
exports.createSubscription = createSubscription;
|
600
|
-
async function createSubscriptionWithCreditCard({ intervalCount, intervalUnit, trialLength, amountInCents, trialAmountInCents, data, creatorName, processorId: processorId, }) {
|
601
|
-
try {
|
602
|
-
let { merchantAuthenticationType } = await getMerchantAuthForProcessor(processorId);
|
603
|
-
return new Promise(async (resolve, reject) => {
|
604
|
-
var interval = new authorizenet_1.APIContracts.PaymentScheduleType.Interval();
|
605
|
-
interval.setLength(intervalCount);
|
606
|
-
interval.setUnit(intervalUnit);
|
607
|
-
var paymentScheduleType = new authorizenet_1.APIContracts.PaymentScheduleType();
|
608
|
-
paymentScheduleType.setInterval(interval);
|
609
|
-
paymentScheduleType.setStartDate(moment()
|
610
|
-
.add(intervalCount, intervalUnit)
|
611
|
-
.add(1, "day")
|
612
|
-
.toISOString()
|
613
|
-
.substring(0, 10));
|
614
|
-
paymentScheduleType.setTotalOccurrences(9999);
|
615
|
-
paymentScheduleType.setTrialOccurrences(trialLength);
|
616
|
-
let creditCard = buildCreditCard(data.payment.creditCard);
|
617
|
-
let paymentType = new authorizenet_1.APIContracts.PaymentType();
|
618
|
-
paymentType.setCreditCard(creditCard);
|
619
|
-
let customerAddress = buildAddress(data.billTo);
|
620
|
-
var arbSubscription = new authorizenet_1.APIContracts.ARBSubscriptionType();
|
621
|
-
arbSubscription.setName(`${creatorName} ${intervalUnit == "days" ? "weekly" : "monthly"} subscription`);
|
622
|
-
arbSubscription.setPaymentSchedule(paymentScheduleType);
|
623
|
-
arbSubscription.setAmount(amountInCents / 100.0);
|
624
|
-
arbSubscription.setTrialAmount((trialAmountInCents || 0) / 100.0);
|
625
|
-
arbSubscription.setBillTo(customerAddress);
|
626
|
-
arbSubscription.setPayment(paymentType);
|
627
|
-
var createRequest = new authorizenet_1.APIContracts.ARBCreateSubscriptionRequest();
|
628
|
-
createRequest.setMerchantAuthentication(merchantAuthenticationType);
|
629
|
-
createRequest.setSubscription(arbSubscription);
|
630
|
-
var ctrl = new authorizenet_1.APIControllers.ARBCreateSubscriptionController(createRequest.getJSON());
|
631
|
-
if (process.env.ENVIRONMENT === "production") {
|
632
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
633
|
-
}
|
634
|
-
ctrl.execute(function () {
|
635
|
-
var apiResponse = ctrl.getResponse();
|
636
|
-
var response = new authorizenet_1.APIContracts.ARBCreateSubscriptionResponse(apiResponse);
|
637
|
-
console.log(JSON.stringify(response, null, 2));
|
638
|
-
if (response != null) {
|
639
|
-
if (response.getMessages().getResultCode() ==
|
640
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
641
|
-
let profileResponse = response.getProfile();
|
642
|
-
let pkCustomerProfileId = profileResponse && profileResponse.getCustomerProfileId();
|
643
|
-
let pkCustomerPaymentProfileId = profileResponse &&
|
644
|
-
profileResponse.getCustomerPaymentProfileId &&
|
645
|
-
profileResponse.getCustomerPaymentProfileId() &&
|
646
|
-
profileResponse.getCustomerPaymentProfileId().getNumericString &&
|
647
|
-
profileResponse
|
648
|
-
.getCustomerPaymentProfileId()
|
649
|
-
.getNumericString()
|
650
|
-
.toString();
|
651
|
-
resolve({
|
652
|
-
pkSubId: response.getSubscriptionId(),
|
653
|
-
paymentProfile: {
|
654
|
-
pkCustomerProfileId,
|
655
|
-
pkCustomerPaymentProfileId,
|
656
|
-
processorId,
|
657
|
-
},
|
658
|
-
});
|
659
|
-
}
|
660
|
-
else {
|
661
|
-
reject(response.getMessages().getMessage()[0].getText());
|
662
|
-
}
|
663
|
-
}
|
664
|
-
else {
|
665
|
-
reject("Null Response.");
|
666
|
-
}
|
667
|
-
});
|
668
|
-
});
|
669
|
-
}
|
670
|
-
catch (err) {
|
671
|
-
console.log(err);
|
672
|
-
throw new Error("Subscription failed to create");
|
673
|
-
}
|
674
|
-
}
|
675
|
-
exports.createSubscriptionWithCreditCard = createSubscriptionWithCreditCard;
|
676
|
-
async function cancelSubscription(subscription, processorId) {
|
677
|
-
let { merchantAuthenticationType } = await getMerchantAuthForProcessor(processorId);
|
678
|
-
var cancelRequest = new authorizenet_1.APIContracts.ARBCancelSubscriptionRequest();
|
679
|
-
cancelRequest.setMerchantAuthentication(merchantAuthenticationType);
|
680
|
-
cancelRequest.setSubscriptionId(subscription.pkSubscriptionId);
|
681
|
-
var ctrl = new authorizenet_1.APIControllers.ARBCancelSubscriptionController(cancelRequest.getJSON());
|
682
|
-
if (process.env.ENVIRONMENT === "production") {
|
683
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
684
|
-
}
|
685
|
-
return new Promise((resolve, reject) => {
|
686
|
-
ctrl.execute(function () {
|
687
|
-
var apiResponse = ctrl.getResponse();
|
688
|
-
var response = new authorizenet_1.APIContracts.ARBCancelSubscriptionResponse(apiResponse);
|
689
|
-
console.log(JSON.stringify(response, null, 2));
|
690
|
-
if (response != null) {
|
691
|
-
if (response.getMessages().getResultCode() ==
|
692
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
693
|
-
resolve(true);
|
694
|
-
}
|
695
|
-
else {
|
696
|
-
reject(response.getMessages().getMessage()[0].getText());
|
697
|
-
}
|
698
|
-
}
|
699
|
-
else {
|
700
|
-
reject("Null Response.");
|
701
|
-
}
|
702
|
-
});
|
703
|
-
});
|
704
|
-
}
|
705
|
-
exports.cancelSubscription = cancelSubscription;
|
706
|
-
async function updateSubscription({ authSubscriptionId, intervalCount, intervalUnit, processorId: processorId, }) {
|
707
|
-
let { merchantAuthenticationType } = await getMerchantAuthForProcessor(processorId);
|
708
|
-
var paymentScheduleType = new authorizenet_1.APIContracts.PaymentScheduleType();
|
709
|
-
paymentScheduleType.setStartDate(moment()
|
710
|
-
.add(intervalCount, intervalUnit)
|
711
|
-
.add(1, "day")
|
712
|
-
.toISOString()
|
713
|
-
.substring(0, 10));
|
714
|
-
var arbSubscription = new authorizenet_1.APIContracts.ARBSubscriptionType();
|
715
|
-
arbSubscription.setPaymentSchedule(paymentScheduleType);
|
716
|
-
var updateRequest = new authorizenet_1.APIContracts.ARBUpdateSubscriptionRequest();
|
717
|
-
updateRequest.setMerchantAuthentication(merchantAuthenticationType);
|
718
|
-
updateRequest.setSubscriptionId(authSubscriptionId);
|
719
|
-
updateRequest.setSubscription(arbSubscription);
|
720
|
-
console.log(JSON.stringify(updateRequest.getJSON(), null, 2));
|
721
|
-
var ctrl = new authorizenet_1.APIControllers.ARBUpdateSubscriptionController(updateRequest.getJSON());
|
722
|
-
if (process.env.ENVIRONMENT === "production") {
|
723
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
724
|
-
}
|
725
|
-
return new Promise((resolve, reject) => {
|
726
|
-
ctrl.execute(function () {
|
727
|
-
var apiResponse = ctrl.getResponse();
|
728
|
-
var response = new authorizenet_1.APIContracts.ARBUpdateSubscriptionResponse(apiResponse);
|
729
|
-
console.log(JSON.stringify(response, null, 2));
|
730
|
-
if (response != null) {
|
731
|
-
if (response.getMessages().getResultCode() ==
|
732
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
733
|
-
resolve(true);
|
734
|
-
}
|
735
|
-
else {
|
736
|
-
reject(response.getMessages().getMessage()[0].getText());
|
737
|
-
}
|
738
|
-
}
|
739
|
-
else {
|
740
|
-
reject("Null Response.");
|
741
|
-
}
|
742
|
-
});
|
743
|
-
});
|
744
|
-
}
|
745
|
-
exports.updateSubscription = updateSubscription;
|
746
|
-
async function getSubscription(subscriptionId, processorId) {
|
747
|
-
let { merchantAuthenticationType } = await getMerchantAuthForProcessor(processorId);
|
748
|
-
var getRequest = new authorizenet_1.APIContracts.ARBGetSubscriptionRequest();
|
749
|
-
getRequest.setMerchantAuthentication(merchantAuthenticationType);
|
750
|
-
getRequest.setSubscriptionId(subscriptionId);
|
751
|
-
getRequest.setIncludeTransactions(true);
|
752
|
-
var ctrl = new authorizenet_1.APIControllers.ARBGetSubscriptionController(getRequest.getJSON());
|
753
|
-
if (process.env.ENVIRONMENT === "production") {
|
754
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
755
|
-
}
|
756
|
-
return new Promise((resolve, reject) => {
|
757
|
-
ctrl.execute(function () {
|
758
|
-
var apiResponse = ctrl.getResponse();
|
759
|
-
var response = new authorizenet_1.APIContracts.ARBGetSubscriptionResponse(apiResponse);
|
760
|
-
if (response != null) {
|
761
|
-
if (response.getMessages().getResultCode() ==
|
762
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
763
|
-
resolve(response.getSubscription());
|
764
|
-
}
|
765
|
-
else {
|
766
|
-
reject(response.getMessages().getMessage()[0].getText());
|
767
|
-
}
|
768
|
-
}
|
769
|
-
else {
|
770
|
-
reject("Null Response.");
|
771
|
-
}
|
772
|
-
});
|
773
|
-
});
|
774
|
-
}
|
775
|
-
exports.getSubscription = getSubscription;
|
776
|
-
async function getSubscriptionStatus(subscriptionId, processorId) {
|
777
|
-
let { merchantAuthenticationType } = await getMerchantAuthForProcessor(processorId);
|
778
|
-
var getRequest = new authorizenet_1.APIContracts.ARBGetSubscriptionStatusRequest();
|
779
|
-
getRequest.setMerchantAuthentication(merchantAuthenticationType);
|
780
|
-
getRequest.setSubscriptionId(subscriptionId);
|
781
|
-
var ctrl = new authorizenet_1.APIControllers.ARBGetSubscriptionStatusController(getRequest.getJSON());
|
782
|
-
if (process.env.ENVIRONMENT === "production") {
|
783
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
784
|
-
}
|
785
|
-
return new Promise((resolve, reject) => {
|
786
|
-
ctrl.execute(function () {
|
787
|
-
var apiResponse = ctrl.getResponse();
|
788
|
-
var response = new authorizenet_1.APIContracts.ARBGetSubscriptionStatusResponse(apiResponse);
|
789
|
-
if (response != null) {
|
790
|
-
if (response.getMessages().getResultCode() ==
|
791
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
792
|
-
resolve(response.getStatus());
|
793
|
-
}
|
794
|
-
else {
|
795
|
-
reject(response.getMessages().getMessage()[0].getText());
|
796
|
-
}
|
797
|
-
}
|
798
|
-
else {
|
799
|
-
reject("Null Response.");
|
800
|
-
}
|
801
|
-
});
|
802
|
-
});
|
803
|
-
}
|
804
|
-
exports.getSubscriptionStatus = getSubscriptionStatus;
|
805
|
-
async function getSubscriptionList(processorId, inactive) {
|
806
|
-
let { merchantAuthenticationType } = await getMerchantAuthForProcessor(processorId);
|
807
|
-
var sorting = new authorizenet_1.APIContracts.ARBGetSubscriptionListSorting();
|
808
|
-
sorting.setOrderDescending(true);
|
809
|
-
sorting.setOrderBy(authorizenet_1.APIContracts.ARBGetSubscriptionListOrderFieldEnum.CREATETIMESTAMPUTC);
|
810
|
-
var listRequest = new authorizenet_1.APIContracts.ARBGetSubscriptionListRequest();
|
811
|
-
listRequest.setMerchantAuthentication(merchantAuthenticationType);
|
812
|
-
listRequest.setSearchType(inactive
|
813
|
-
? authorizenet_1.APIContracts.ARBGetSubscriptionListSearchTypeEnum.SUBSCRIPTIONINACTIVE
|
814
|
-
: authorizenet_1.APIContracts.ARBGetSubscriptionListSearchTypeEnum.SUBSCRIPTIONACTIVE);
|
815
|
-
listRequest.setSorting(sorting);
|
816
|
-
console.log(JSON.stringify(listRequest.getJSON(), null, 2));
|
817
|
-
var ctrl = new authorizenet_1.APIControllers.ARBGetSubscriptionListController(listRequest.getJSON());
|
818
|
-
if (process.env.ENVIRONMENT === "production") {
|
819
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
820
|
-
}
|
821
|
-
return new Promise((resolve, reject) => {
|
822
|
-
ctrl.execute(function () {
|
823
|
-
var apiResponse = ctrl.getResponse();
|
824
|
-
var response = new authorizenet_1.APIContracts.ARBGetSubscriptionListResponse(apiResponse);
|
825
|
-
if (response != null) {
|
826
|
-
if (response.getMessages().getResultCode() ==
|
827
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
828
|
-
console.log("Total Results: " + response.getTotalNumInResultSet());
|
829
|
-
var subscriptions = response
|
830
|
-
.getSubscriptionDetails()
|
831
|
-
.getSubscriptionDetail();
|
832
|
-
resolve(subscriptions);
|
833
|
-
}
|
834
|
-
else {
|
835
|
-
console.log("Result Code: " + response.getMessages().getResultCode());
|
836
|
-
console.log("Error Code: " + response.getMessages().getMessage()[0].getCode());
|
837
|
-
console.log("Error message: " + response.getMessages().getMessage()[0].getText());
|
838
|
-
reject();
|
839
|
-
}
|
840
|
-
}
|
841
|
-
else {
|
842
|
-
reject();
|
843
|
-
}
|
844
|
-
});
|
845
|
-
});
|
846
|
-
}
|
847
|
-
exports.getSubscriptionList = getSubscriptionList;
|
848
|
-
async function voidTransaction(transactionId, processorId) {
|
849
|
-
let { merchantAuthenticationType } = await getMerchantAuthForProcessor(processorId);
|
850
|
-
var transactionRequestType = new authorizenet_1.APIContracts.TransactionRequestType();
|
851
|
-
transactionRequestType.setTransactionType(authorizenet_1.APIContracts.TransactionTypeEnum.VOIDTRANSACTION);
|
852
|
-
transactionRequestType.setRefTransId(transactionId);
|
853
|
-
var createRequest = new authorizenet_1.APIContracts.CreateTransactionRequest();
|
854
|
-
createRequest.setMerchantAuthentication(merchantAuthenticationType);
|
855
|
-
createRequest.setTransactionRequest(transactionRequestType);
|
856
|
-
var ctrl = new authorizenet_1.APIControllers.CreateTransactionController(createRequest.getJSON());
|
857
|
-
if (process.env.ENVIRONMENT === "production") {
|
858
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
859
|
-
}
|
860
|
-
return new Promise((resolve, reject) => {
|
861
|
-
ctrl.execute(function () {
|
862
|
-
var apiResponse = ctrl.getResponse();
|
863
|
-
var response = new authorizenet_1.APIContracts.CreateTransactionResponse(apiResponse);
|
864
|
-
if (response != null) {
|
865
|
-
if (response.getMessages().getResultCode() ==
|
866
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
867
|
-
if (response.getTransactionResponse().getMessages() != null) {
|
868
|
-
resolve(true);
|
869
|
-
}
|
870
|
-
else {
|
871
|
-
if (response.getTransactionResponse().getErrors() != null) {
|
872
|
-
reject(response
|
873
|
-
.getTransactionResponse()
|
874
|
-
.getErrors()
|
875
|
-
.getError()[0]
|
876
|
-
.getErrorText());
|
877
|
-
}
|
878
|
-
}
|
879
|
-
}
|
880
|
-
else {
|
881
|
-
console.log("Failed Transaction. ");
|
882
|
-
if (response.getTransactionResponse() != null &&
|
883
|
-
response.getTransactionResponse().getErrors() != null) {
|
884
|
-
reject(response
|
885
|
-
.getTransactionResponse()
|
886
|
-
.getErrors()
|
887
|
-
.getError()[0]
|
888
|
-
.getErrorText());
|
889
|
-
}
|
890
|
-
else {
|
891
|
-
reject(response.getMessages().getMessage()[0].getText());
|
892
|
-
}
|
893
|
-
}
|
894
|
-
}
|
895
|
-
else {
|
896
|
-
console.log("Null Response.");
|
897
|
-
}
|
898
|
-
});
|
899
|
-
});
|
900
|
-
}
|
901
|
-
exports.voidTransaction = voidTransaction;
|
902
|
-
const updateUserPaymentProfile = async (userId, customerProfileId, processorId, pkCustomerPaymentProfileId) => {
|
903
|
-
console.log("Update payment profile");
|
904
|
-
let profile = await customer_profile_1.default.findOne({
|
905
|
-
where: { userId: userId },
|
906
|
-
});
|
907
|
-
if (!profile) {
|
908
|
-
console.log("Create new payment profile");
|
909
|
-
profile = await customer_profile_1.default.create({
|
910
|
-
userId: userId,
|
911
|
-
customerProfileId: customerProfileId,
|
912
|
-
defaultPaymentProfileId: pkCustomerPaymentProfileId,
|
913
|
-
processorId,
|
914
|
-
});
|
915
|
-
}
|
916
|
-
else {
|
917
|
-
profile.customerProfileId = customerProfileId;
|
918
|
-
profile.defaultPaymentProfileId = pkCustomerPaymentProfileId;
|
919
|
-
profile.processorId = processorId;
|
920
|
-
await profile.save();
|
921
|
-
}
|
922
|
-
return profile;
|
923
|
-
};
|
924
|
-
exports.updateUserPaymentProfile = updateUserPaymentProfile;
|
925
|
-
async function getTransactionsForCustomerProfile({ customerProfileId, processorId, }) {
|
926
|
-
let { merchantAuthenticationType } = await getMerchantAuthForProcessor(processorId);
|
927
|
-
var paging = new authorizenet_1.APIContracts.Paging();
|
928
|
-
paging.setLimit(10);
|
929
|
-
paging.setOffset(1);
|
930
|
-
var sorting = new authorizenet_1.APIContracts.TransactionListSorting();
|
931
|
-
sorting.setOrderBy(authorizenet_1.APIContracts.TransactionListOrderFieldEnum.ID);
|
932
|
-
sorting.setOrderDescending(true);
|
933
|
-
var getRequest = new authorizenet_1.APIContracts.GetTransactionListForCustomerRequest();
|
934
|
-
getRequest.setMerchantAuthentication(merchantAuthenticationType);
|
935
|
-
getRequest.setCustomerProfileId(customerProfileId);
|
936
|
-
getRequest.setPaging(paging);
|
937
|
-
getRequest.setSorting(sorting);
|
938
|
-
console.log(JSON.stringify(getRequest.getJSON(), null, 2));
|
939
|
-
var ctrl = new authorizenet_1.APIControllers.GetTransactionListForCustomerController(getRequest.getJSON());
|
940
|
-
if (process.env.ENVIRONMENT === "production") {
|
941
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
942
|
-
}
|
943
|
-
return new Promise((resolve, reject) => {
|
944
|
-
ctrl.execute(function () {
|
945
|
-
var apiResponse = ctrl.getResponse();
|
946
|
-
console.log(apiResponse);
|
947
|
-
var response = new authorizenet_1.APIContracts.GetTransactionListResponse(apiResponse);
|
948
|
-
console.log(response.getTransactions());
|
949
|
-
if (response != null) {
|
950
|
-
if (response.getMessages().getResultCode() ==
|
951
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
952
|
-
if (response.getTransactions() != null) {
|
953
|
-
var transactions = response.getTransactions().getTransaction();
|
954
|
-
resolve(transactions.map((t) => {
|
955
|
-
return {
|
956
|
-
transId: t.getTransId(),
|
957
|
-
amountInCents: t.getSettleAmount() * 100,
|
958
|
-
status: t.getTransactionStatus(),
|
959
|
-
};
|
960
|
-
}));
|
961
|
-
}
|
962
|
-
else {
|
963
|
-
reject(response.getMessages().getMessage()[0].getText());
|
964
|
-
}
|
965
|
-
}
|
966
|
-
else {
|
967
|
-
console.log("Failed Transaction. ");
|
968
|
-
reject(response.getMessages().getMessage()[0].getText());
|
969
|
-
}
|
970
|
-
}
|
971
|
-
else {
|
972
|
-
console.log("Null Response.");
|
973
|
-
}
|
974
|
-
});
|
975
|
-
});
|
976
|
-
}
|
977
|
-
exports.getTransactionsForCustomerProfile = getTransactionsForCustomerProfile;
|
978
|
-
async function refundTransaction({ transId, creditCard, customerProfile, amountInCents, processorId, }) {
|
979
|
-
let { merchantAuthenticationType } = await getMerchantAuthForProcessor(processorId);
|
980
|
-
let cc = new authorizenet_1.APIContracts.CreditCardType();
|
981
|
-
cc.cardNumber = creditCard === null || creditCard === void 0 ? void 0 : creditCard.cardNumber;
|
982
|
-
cc.expirationDate = creditCard === null || creditCard === void 0 ? void 0 : creditCard.expirationDate;
|
983
|
-
var paymentType = new authorizenet_1.APIContracts.PaymentType();
|
984
|
-
paymentType.setCreditCard(cc);
|
985
|
-
var transactionRequestType = new authorizenet_1.APIContracts.TransactionRequestType();
|
986
|
-
transactionRequestType.setTransactionType(authorizenet_1.APIContracts.TransactionTypeEnum.REFUNDTRANSACTION);
|
987
|
-
transactionRequestType.setAmount(amountInCents / 100.0);
|
988
|
-
transactionRequestType.setRefTransId(transId);
|
989
|
-
// transactionRequestType.setCustomer(customerProfile);
|
990
|
-
transactionRequestType.setPayment(paymentType);
|
991
|
-
var createRequest = new authorizenet_1.APIContracts.CreateTransactionRequest();
|
992
|
-
createRequest.setMerchantAuthentication(merchantAuthenticationType);
|
993
|
-
createRequest.setTransactionRequest(transactionRequestType);
|
994
|
-
//pretty print request
|
995
|
-
console.log(JSON.stringify(createRequest.getJSON(), null, 2));
|
996
|
-
var ctrl = new authorizenet_1.APIControllers.CreateTransactionController(createRequest.getJSON());
|
997
|
-
if (process.env.ENVIRONMENT === "production") {
|
998
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
999
|
-
}
|
1000
|
-
return new Promise((resolve, reject) => {
|
1001
|
-
ctrl.execute(function () {
|
1002
|
-
var apiResponse = ctrl.getResponse();
|
1003
|
-
var response = new authorizenet_1.APIContracts.CreateTransactionResponse(apiResponse);
|
1004
|
-
if (response != null) {
|
1005
|
-
if (response.getMessages().getResultCode() ==
|
1006
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
1007
|
-
if (response.getTransactionResponse().getMessages() != null) {
|
1008
|
-
resolve({
|
1009
|
-
refundTransactionId: response
|
1010
|
-
.getTransactionResponse()
|
1011
|
-
.getTransId(),
|
1012
|
-
});
|
1013
|
-
}
|
1014
|
-
else {
|
1015
|
-
reject(response
|
1016
|
-
.getTransactionResponse()
|
1017
|
-
.getErrors()
|
1018
|
-
.getError()[0]
|
1019
|
-
.getErrorText());
|
1020
|
-
}
|
1021
|
-
}
|
1022
|
-
else {
|
1023
|
-
if (response.getTransactionResponse() != null &&
|
1024
|
-
response.getTransactionResponse().getErrors() != null) {
|
1025
|
-
reject(response
|
1026
|
-
.getTransactionResponse()
|
1027
|
-
.getErrors()
|
1028
|
-
.getError()[0]
|
1029
|
-
.getErrorText());
|
1030
|
-
}
|
1031
|
-
else {
|
1032
|
-
reject(response.getMessages().getMessage()[0].getText());
|
1033
|
-
}
|
1034
|
-
}
|
1035
|
-
}
|
1036
|
-
else {
|
1037
|
-
reject("Null Response.");
|
1038
|
-
}
|
1039
|
-
});
|
1040
|
-
});
|
1041
|
-
}
|
1042
|
-
exports.refundTransaction = refundTransaction;
|
1043
|
-
async function getTransactionStatus({ transId, processorId, }) {
|
1044
|
-
let { merchantAuthenticationType } = await getMerchantAuthForProcessor(processorId);
|
1045
|
-
var getRequest = new authorizenet_1.APIContracts.GetTransactionDetailsRequest();
|
1046
|
-
getRequest.setMerchantAuthentication(merchantAuthenticationType);
|
1047
|
-
getRequest.setTransId(transId);
|
1048
|
-
console.log(JSON.stringify(getRequest.getJSON(), null, 2));
|
1049
|
-
var ctrl = new authorizenet_1.APIControllers.GetTransactionDetailsController(getRequest.getJSON());
|
1050
|
-
if (process.env.ENVIRONMENT === "production") {
|
1051
|
-
ctrl.setEnvironment(authorizenet_1.Constants.endpoint.production);
|
1052
|
-
}
|
1053
|
-
return new Promise((resolve, reject) => {
|
1054
|
-
ctrl.execute(function () {
|
1055
|
-
var apiResponse = ctrl.getResponse();
|
1056
|
-
var response = new authorizenet_1.APIContracts.GetTransactionDetailsResponse(apiResponse);
|
1057
|
-
if (response != null) {
|
1058
|
-
if (response.getMessages().getResultCode() ==
|
1059
|
-
authorizenet_1.APIContracts.MessageTypeEnum.OK) {
|
1060
|
-
let payment = response.getTransaction().getPayment();
|
1061
|
-
let customer = response.getTransaction().getCustomer();
|
1062
|
-
resolve({
|
1063
|
-
status: response.getTransaction().getTransactionStatus(),
|
1064
|
-
transId: response.getTransaction().getTransId(),
|
1065
|
-
code: response.getTransaction().getResponseCode(),
|
1066
|
-
settleAmountInCents: response.getTransaction().getSettleAmount() * 100,
|
1067
|
-
creditCard: payment && payment.getCreditCard(),
|
1068
|
-
customerProfile: customer,
|
1069
|
-
});
|
1070
|
-
}
|
1071
|
-
else {
|
1072
|
-
reject(response.getMessages().getMessage()[0].getText());
|
1073
|
-
}
|
1074
|
-
}
|
1075
|
-
else {
|
1076
|
-
reject("Null Response.");
|
1077
|
-
}
|
1078
|
-
});
|
1079
|
-
});
|
1080
|
-
}
|
1081
|
-
exports.getTransactionStatus = getTransactionStatus;
|
1082
|
-
exports.default = {
|
1083
|
-
createCustomerProfile: exports.createCustomerProfile,
|
1084
|
-
getCustomerProfile: exports.getCustomerProfile,
|
1085
|
-
addPaymentProfile: exports.addPaymentProfile,
|
1086
|
-
deleteCustomerProfile: exports.deleteCustomerProfile,
|
1087
|
-
updateCustomerProfile: exports.updateCustomerProfile,
|
1088
|
-
purchaseCreditsWithCustomerProfile: exports.purchaseCreditsWithCustomerProfile,
|
1089
|
-
purchaseCreditsWithCreditCardAndCreatorProfile: exports.purchaseCreditsWithCreditCardAndCreatorProfile,
|
1090
|
-
createSubscription,
|
1091
|
-
cancelSubscription,
|
1092
|
-
getSubscription,
|
1093
|
-
getSubscriptionStatus,
|
1094
|
-
chargeCustomerByPaymentProfile: exports.chargeCustomerByPaymentProfile,
|
1095
|
-
getSubscriptionList,
|
1096
|
-
updateUserPaymentProfile: exports.updateUserPaymentProfile,
|
1097
|
-
voidTransaction,
|
1098
|
-
chargeCreditCardAndCreateProfile: exports.chargeCreditCardAndCreateProfile,
|
1099
|
-
getTransactionsForCustomerProfile,
|
1100
|
-
getTransactionStatus,
|
1101
|
-
refundTransaction,
|
1102
|
-
};
|
1103
|
-
//# sourceMappingURL=pk-client.js.map
|