@stamhoofd/backend 2.39.1 → 2.40.1
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/eslint.config.mjs +5 -0
- package/index.ts +81 -74
- package/jest.config.cjs +10 -0
- package/migrations.ts +16 -14
- package/package.json +11 -11
- package/src/crons/clear-excel-cache.test.ts +48 -50
- package/src/crons/clear-excel-cache.ts +18 -18
- package/src/crons/setup-steps.ts +2 -2
- package/src/crons.ts +325 -306
- package/src/decoders/StringArrayDecoder.ts +7 -7
- package/src/decoders/StringNullableDecoder.ts +1 -2
- package/src/email-recipient-loaders/members.ts +22 -22
- package/src/endpoints/admin/memberships/ChargeMembershipsEndpoint.ts +8 -9
- package/src/endpoints/admin/memberships/GetChargeMembershipsSummaryEndpoint.ts +39 -40
- package/src/endpoints/admin/organizations/GetOrganizationsCountEndpoint.ts +8 -8
- package/src/endpoints/admin/organizations/GetOrganizationsEndpoint.ts +44 -45
- package/src/endpoints/admin/organizations/PatchOrganizationsEndpoint.ts +58 -57
- package/src/endpoints/auth/CreateAdminEndpoint.ts +48 -45
- package/src/endpoints/auth/CreateTokenEndpoint.test.ts +31 -31
- package/src/endpoints/auth/CreateTokenEndpoint.ts +146 -147
- package/src/endpoints/auth/DeleteTokenEndpoint.ts +7 -7
- package/src/endpoints/auth/DeleteUserEndpoint.ts +15 -15
- package/src/endpoints/auth/ForgotPasswordEndpoint.ts +17 -18
- package/src/endpoints/auth/GetOtherUserEndpoint.ts +9 -10
- package/src/endpoints/auth/GetUserEndpoint.test.ts +32 -35
- package/src/endpoints/auth/GetUserEndpoint.ts +5 -6
- package/src/endpoints/auth/PatchApiUserEndpoint.ts +35 -33
- package/src/endpoints/auth/PatchUserEndpoint.ts +55 -52
- package/src/endpoints/auth/PollEmailVerificationEndpoint.ts +9 -9
- package/src/endpoints/auth/RetryEmailVerificationEndpoint.ts +8 -8
- package/src/endpoints/auth/SignupEndpoint.ts +37 -36
- package/src/endpoints/auth/VerifyEmailEndpoint.ts +29 -28
- package/src/endpoints/global/addresses/SearchRegionsEndpoint.ts +33 -33
- package/src/endpoints/global/addresses/ValidateAddressEndpoint.ts +7 -7
- package/src/endpoints/global/caddy/CheckDomainCertEndpoint.ts +37 -37
- package/src/endpoints/global/email/CreateEmailEndpoint.ts +30 -30
- package/src/endpoints/global/email/GetEmailAddressEndpoint.ts +13 -13
- package/src/endpoints/global/email/GetEmailEndpoint.ts +13 -13
- package/src/endpoints/global/email/ManageEmailAddressEndpoint.ts +16 -16
- package/src/endpoints/global/email/PatchEmailEndpoint.ts +25 -25
- package/src/endpoints/global/events/GetEventsEndpoint.ts +43 -44
- package/src/endpoints/global/events/PatchEventsEndpoint.ts +127 -172
- package/src/endpoints/global/files/ExportToExcelEndpoint.ts +49 -50
- package/src/endpoints/global/files/GetFileCache.ts +13 -13
- package/src/endpoints/global/files/UploadFile.ts +51 -54
- package/src/endpoints/global/files/UploadImage.ts +53 -53
- package/src/endpoints/global/groups/GetGroupsEndpoint.ts +25 -25
- package/src/endpoints/global/members/GetMemberFamilyEndpoint.ts +24 -23
- package/src/endpoints/global/members/GetMembersCountEndpoint.ts +8 -8
- package/src/endpoints/global/members/GetMembersEndpoint.ts +105 -102
- package/src/endpoints/global/members/PatchOrganizationMembersEndpoint.ts +240 -239
- package/src/endpoints/global/organizations/CheckRegisterCodeEndpoint.ts +12 -14
- package/src/endpoints/global/organizations/CreateOrganizationEndpoint.test.ts +32 -33
- package/src/endpoints/global/organizations/CreateOrganizationEndpoint.ts +48 -57
- package/src/endpoints/global/organizations/GetOrganizationFromDomainEndpoint.test.ts +21 -22
- package/src/endpoints/global/organizations/GetOrganizationFromDomainEndpoint.ts +28 -28
- package/src/endpoints/global/organizations/GetOrganizationFromUriEndpoint.ts +18 -18
- package/src/endpoints/global/organizations/SearchOrganizationEndpoint.test.ts +20 -20
- package/src/endpoints/global/organizations/SearchOrganizationEndpoint.ts +17 -17
- package/src/endpoints/global/payments/StripeWebhookEndpoint.ts +81 -75
- package/src/endpoints/global/platform/GetPlatformAdminsEndpoint.ts +14 -14
- package/src/endpoints/global/platform/GetPlatformEnpoint.ts +11 -11
- package/src/endpoints/global/platform/PatchPlatformEnpoint.ts +71 -68
- package/src/endpoints/global/registration/GetPaymentRegistrations.ts +27 -27
- package/src/endpoints/global/registration/GetUserBillingStatusEndpoint.ts +30 -30
- package/src/endpoints/global/registration/GetUserDetailedBillingStatusEndpoint.ts +34 -34
- package/src/endpoints/global/registration/GetUserDocumentsEndpoint.ts +26 -26
- package/src/endpoints/global/registration/GetUserMembersEndpoint.ts +12 -12
- package/src/endpoints/global/registration/PatchUserMembersEndpoint.ts +90 -90
- package/src/endpoints/global/registration/RegisterMembersEndpoint.test.ts +118 -121
- package/src/endpoints/global/registration/RegisterMembersEndpoint.ts +362 -350
- package/src/endpoints/global/registration-periods/GetRegistrationPeriodsEndpoint.ts +8 -9
- package/src/endpoints/global/registration-periods/PatchRegistrationPeriodsEndpoint.ts +21 -21
- package/src/endpoints/global/webshops/GetWebshopFromDomainEndpoint.ts +65 -65
- package/src/endpoints/organization/dashboard/billing/GetOrganizationBillingStatusEndpoint.ts +9 -9
- package/src/endpoints/organization/dashboard/billing/GetOrganizationDetailedBillingStatusEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/documents/GetDocumentTemplateXML.ts +17 -17
- package/src/endpoints/organization/dashboard/documents/GetDocumentTemplatesEndpoint.ts +21 -21
- package/src/endpoints/organization/dashboard/documents/GetDocumentsEndpoint.ts +15 -15
- package/src/endpoints/organization/dashboard/documents/PatchDocumentEndpoint.ts +52 -52
- package/src/endpoints/organization/dashboard/documents/PatchDocumentTemplateEndpoint.ts +37 -37
- package/src/endpoints/organization/dashboard/email/CheckEmailBouncesEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/email/EmailEndpoint.ts +113 -112
- package/src/endpoints/organization/dashboard/email-templates/GetEmailTemplatesEndpoint.ts +29 -29
- package/src/endpoints/organization/dashboard/email-templates/PatchEmailTemplatesEndpoint.ts +48 -47
- package/src/endpoints/organization/dashboard/mollie/CheckMollieEndpoint.ts +22 -21
- package/src/endpoints/organization/dashboard/mollie/ConnectMollieEndpoint.ts +13 -14
- package/src/endpoints/organization/dashboard/mollie/DisconnectMollieEndpoint.ts +12 -13
- package/src/endpoints/organization/dashboard/mollie/GetMollieDashboardEndpoint.ts +24 -24
- package/src/endpoints/organization/dashboard/nolt/CreateNoltTokenEndpoint.ts +10 -12
- package/src/endpoints/organization/dashboard/organization/GetOrganizationArchivedGroups.ts +14 -14
- package/src/endpoints/organization/dashboard/organization/GetOrganizationDeletedGroups.ts +13 -13
- package/src/endpoints/organization/dashboard/organization/GetOrganizationSSOEndpoint.ts +12 -12
- package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.test.ts +120 -124
- package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.ts +172 -173
- package/src/endpoints/organization/dashboard/organization/SetOrganizationDomainEndpoint.ts +88 -89
- package/src/endpoints/organization/dashboard/organization/SetOrganizationSSOEndpoint.ts +12 -12
- package/src/endpoints/organization/dashboard/payments/GetMemberBalanceEndpoint.ts +17 -17
- package/src/endpoints/organization/dashboard/payments/GetPaymentsCountEndpoint.ts +8 -8
- package/src/endpoints/organization/dashboard/payments/GetPaymentsEndpoint.ts +66 -67
- package/src/endpoints/organization/dashboard/payments/PatchBalanceItemsEndpoint.ts +47 -47
- package/src/endpoints/organization/dashboard/payments/PatchPaymentsEndpoint.ts +93 -91
- package/src/endpoints/organization/dashboard/registration-periods/GetOrganizationRegistrationPeriodsEndpoint.ts +16 -17
- package/src/endpoints/organization/dashboard/registration-periods/PatchOrganizationRegistrationPeriodsEndpoint.ts +170 -167
- package/src/endpoints/organization/dashboard/registration-periods/SetupStepReviewEndpoint.ts +25 -24
- package/src/endpoints/organization/dashboard/stripe/ConnectStripeEndpoint.ts +22 -23
- package/src/endpoints/organization/dashboard/stripe/DeleteStripeAccountEndpoint.ts +22 -22
- package/src/endpoints/organization/dashboard/stripe/GetStripeAccountLinkEndpoint.ts +17 -18
- package/src/endpoints/organization/dashboard/stripe/GetStripeAccountsEndpoint.ts +8 -9
- package/src/endpoints/organization/dashboard/stripe/GetStripeLoginLinkEndpoint.ts +17 -18
- package/src/endpoints/organization/dashboard/stripe/UpdateStripeAccountEndpoint.ts +14 -15
- package/src/endpoints/organization/dashboard/users/CreateApiUserEndpoint.ts +19 -19
- package/src/endpoints/organization/dashboard/users/DeleteUserEndpoint.ts +19 -19
- package/src/endpoints/organization/dashboard/users/GetApiUsersEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/users/GetOrganizationAdminsEndpoint.ts +12 -12
- package/src/endpoints/organization/dashboard/webshops/CreateWebshopEndpoint.ts +103 -100
- package/src/endpoints/organization/dashboard/webshops/DeleteWebshopEndpoint.ts +11 -12
- package/src/endpoints/organization/dashboard/webshops/GetDiscountCodesEndpoint.ts +15 -15
- package/src/endpoints/organization/dashboard/webshops/GetWebshopOrdersEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/webshops/GetWebshopTicketsEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/webshops/GetWebshopUriAvailabilityEndpoint.ts +23 -23
- package/src/endpoints/organization/dashboard/webshops/PatchDiscountCodesEndpoint.ts +54 -52
- package/src/endpoints/organization/dashboard/webshops/PatchWebshopEndpoint.ts +84 -81
- package/src/endpoints/organization/dashboard/webshops/PatchWebshopOrdersEndpoint.ts +120 -111
- package/src/endpoints/organization/dashboard/webshops/PatchWebshopTicketsEndpoint.ts +24 -24
- package/src/endpoints/organization/dashboard/webshops/VerifyWebshopDomainEndpoint.ts +18 -18
- package/src/endpoints/organization/shared/ExchangePaymentEndpoint.ts +141 -130
- package/src/endpoints/organization/shared/GetDocumentHtml.ts +25 -25
- package/src/endpoints/organization/shared/GetPaymentEndpoint.ts +18 -18
- package/src/endpoints/organization/shared/auth/GetOrganizationEndpoint.test.ts +36 -37
- package/src/endpoints/organization/shared/auth/GetOrganizationEndpoint.ts +9 -9
- package/src/endpoints/organization/shared/auth/OpenIDConnectCallbackEndpoint.ts +11 -11
- package/src/endpoints/organization/shared/auth/OpenIDConnectStartEndpoint.ts +28 -27
- package/src/endpoints/organization/webshops/CheckWebshopDiscountCodesEndpoint.ts +20 -20
- package/src/endpoints/organization/webshops/GetOrderByPaymentEndpoint.ts +22 -22
- package/src/endpoints/organization/webshops/GetOrderEndpoint.ts +14 -14
- package/src/endpoints/organization/webshops/GetTicketsEndpoint.ts +57 -56
- package/src/endpoints/organization/webshops/GetWebshopEndpoint.test.ts +65 -66
- package/src/endpoints/organization/webshops/GetWebshopEndpoint.ts +18 -17
- package/src/endpoints/organization/webshops/PlaceOrderEndpoint.test.ts +124 -128
- package/src/endpoints/organization/webshops/PlaceOrderEndpoint.ts +154 -145
- package/src/excel-loaders/members.ts +275 -273
- package/src/excel-loaders/payments.ts +155 -156
- package/src/helpers/AddressValidator.test.ts +32 -32
- package/src/helpers/AddressValidator.ts +128 -122
- package/src/helpers/AdminPermissionChecker.ts +339 -236
- package/src/helpers/AuthenticatedStructures.ts +233 -134
- package/src/helpers/BuckarooHelper.ts +134 -134
- package/src/helpers/CheckSettlements.ts +94 -88
- package/src/helpers/Context.ts +87 -86
- package/src/helpers/CookieHelper.ts +23 -22
- package/src/helpers/EmailResumer.ts +10 -10
- package/src/helpers/FileCache.ts +62 -62
- package/src/helpers/ForwardHandler.test.ts +122 -124
- package/src/helpers/ForwardHandler.ts +76 -70
- package/src/helpers/MemberUserSyncer.ts +101 -96
- package/src/helpers/MembershipCharger.ts +69 -69
- package/src/helpers/MembershipHelper.ts +11 -12
- package/src/helpers/OpenIDConnectHelper.ts +85 -82
- package/src/helpers/PeriodHelper.ts +65 -70
- package/src/helpers/StripeHelper.ts +146 -137
- package/src/helpers/StripePayoutChecker.ts +51 -52
- package/src/helpers/ViesHelper.ts +46 -44
- package/src/helpers/fetchToAsyncIterator.ts +14 -14
- package/src/helpers/xlsxAddressTransformerColumnFactory.ts +58 -60
- package/src/middleware/ContextMiddleware.ts +5 -5
- package/src/migrations/1646578856-validate-addresses.ts +6 -9
- package/src/seeds/0000000000-example.ts +3 -5
- package/src/seeds/1715028563-user-permissions.ts +16 -18
- package/src/seeds/1722256498-group-update-occupancy.ts +12 -12
- package/src/seeds/1722344162-sync-member-users.ts +14 -15
- package/src/seeds/1722344162-update-membership.ts +6 -6
- package/src/seeds/1726055544-balance-item-paid.ts +4 -4
- package/src/seeds/1726055545-balance-item-pending.ts +4 -4
- package/src/seeds/1726494419-update-cached-outstanding-balance.ts +16 -16
- package/src/seeds/1726494420-update-cached-outstanding-balance-from-items.ts +12 -12
- package/src/seeds/1726572303-schedule-stock-updates.ts +12 -12
- package/src/seeds/1726847064-setup-steps.ts +16 -0
- package/src/sql-filters/balance-item-payments.ts +7 -7
- package/src/sql-filters/events.ts +14 -14
- package/src/sql-filters/members.ts +96 -96
- package/src/sql-filters/organizations.ts +139 -75
- package/src/sql-filters/payments.ts +28 -28
- package/src/sql-filters/registrations.ts +14 -14
- package/src/sql-sorters/events.ts +25 -25
- package/src/sql-sorters/members.ts +26 -26
- package/src/sql-sorters/organizations.ts +36 -36
- package/src/sql-sorters/payments.ts +26 -26
- package/tests/e2e/stock.test.ts +616 -621
- package/tests/e2e/tickets.test.ts +255 -260
- package/tests/helpers/StripeMocker.ts +177 -179
- package/tests/helpers/TestServer.ts +9 -9
- package/tests/jest.global.setup.ts +14 -13
- package/tests/jest.setup.ts +33 -32
- package/.eslintrc.js +0 -61
- package/jest.config.js +0 -11
- package/src/helpers/SetupStepsUpdater.ts +0 -359
- package/src/seeds/1724076679-setup-steps.ts +0 -16
|
@@ -17,108 +17,108 @@ export class BuckarooHelper {
|
|
|
17
17
|
|
|
18
18
|
getEncodedContent(content: string) {
|
|
19
19
|
if (content) {
|
|
20
|
-
return crypto.createHash('md5').update(content).digest(
|
|
20
|
+
return crypto.createHash('md5').update(content).digest('base64');
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
return content;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
calculateHMAC(method: string, url: string, content: string): string {
|
|
27
|
-
method = method.toUpperCase()
|
|
27
|
+
method = method.toUpperCase();
|
|
28
28
|
|
|
29
29
|
// Remove protocol from url
|
|
30
|
-
url = url.replace(/^https?:\/\//, '')
|
|
30
|
+
url = url.replace(/^https?:\/\//, '');
|
|
31
31
|
|
|
32
32
|
// Uri encode
|
|
33
|
-
url = encodeURIComponent(url)
|
|
33
|
+
url = encodeURIComponent(url);
|
|
34
34
|
|
|
35
35
|
// To lowercase (should be last)
|
|
36
|
-
url = url.toLowerCase()
|
|
36
|
+
url = url.toLowerCase();
|
|
37
37
|
|
|
38
|
-
const timestamp = Math.floor(Date.now() / 1000)
|
|
38
|
+
const timestamp = Math.floor(Date.now() / 1000);
|
|
39
39
|
|
|
40
40
|
// Nonce: A random sequence of characters, this should differ from for each request.
|
|
41
|
-
const nonce = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
|
|
41
|
+
const nonce = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
42
42
|
|
|
43
|
-
const encodedContent = this.getEncodedContent(content)
|
|
43
|
+
const encodedContent = this.getEncodedContent(content);
|
|
44
44
|
const rawData = this.key + method + url + timestamp + nonce + encodedContent;
|
|
45
45
|
|
|
46
46
|
// The HMAC SHA256 of rawData using secret
|
|
47
47
|
const hash = crypto.createHmac('sha256', this.secret).update(rawData).digest('base64');
|
|
48
48
|
|
|
49
|
-
return
|
|
49
|
+
return 'hmac ' + this.key + ':' + hash + ':' + nonce + ':' + timestamp;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
async request(method:
|
|
53
|
-
|
|
54
|
-
const json = content ? JSON.stringify(content) : "";
|
|
52
|
+
async request(method: 'GET' | 'POST', uri: string, content: any) {
|
|
53
|
+
const json = content ? JSON.stringify(content) : '';
|
|
55
54
|
// Finally, if you want to perform live transactions, sent the API requests to https://checkout.buckaroo.nl/json/Transaction
|
|
56
|
-
const url = (!this.testMode ?
|
|
55
|
+
const url = (!this.testMode ? 'https://checkout.buckaroo.nl' : 'https://testcheckout.buckaroo.nl') + uri;
|
|
57
56
|
|
|
58
|
-
console.log(
|
|
57
|
+
console.log('[BUCKAROO REQUEST]', method, url, content ? '\n [BUCKAROO REQUEST] ' : undefined, json);
|
|
59
58
|
|
|
60
59
|
const response = await axios.request({
|
|
61
60
|
method,
|
|
62
61
|
url,
|
|
63
62
|
headers: {
|
|
64
|
-
'Content-Type': json.length > 0 ? 'application/json' :
|
|
65
|
-
'Authorization': this.calculateHMAC(method, url, json)
|
|
63
|
+
'Content-Type': json.length > 0 ? 'application/json' : 'text/plain',
|
|
64
|
+
'Authorization': this.calculateHMAC(method, url, json),
|
|
66
65
|
},
|
|
67
|
-
data: json
|
|
68
|
-
|
|
69
|
-
})
|
|
70
|
-
console.log(
|
|
71
|
-
return response.data
|
|
66
|
+
data: json,
|
|
67
|
+
|
|
68
|
+
});
|
|
69
|
+
console.log('[BUCKAROO RESPONSE]', method, url, '\n[BUCKAROO RESPONSE]', JSON.stringify(response.data));
|
|
70
|
+
return response.data;
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
async createTest(): Promise<boolean> {
|
|
75
74
|
const service = {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
75
|
+
Name: 'bancontactmrcash',
|
|
76
|
+
Action: 'Pay',
|
|
77
|
+
Parameters: [
|
|
78
|
+
{
|
|
79
|
+
Name: 'savetoken',
|
|
80
|
+
Value: 'false',
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
};
|
|
85
84
|
const data = {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
Currency: 'EUR',
|
|
86
|
+
AmountDebit: '0.01',
|
|
87
|
+
Invoice: 'TESTPAYMENT-' + (new Date().getTime()) + '-' + Math.round(Math.random() * 100000),
|
|
88
|
+
ClientIP: {
|
|
89
|
+
Type: 0, // 0 = ipv4, 1 = ipv6
|
|
90
|
+
Address: '0.0.0.0',
|
|
92
91
|
},
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
service
|
|
96
|
-
]
|
|
92
|
+
Services: {
|
|
93
|
+
ServiceList: [
|
|
94
|
+
service,
|
|
95
|
+
],
|
|
97
96
|
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
97
|
+
ContinueOnIncomplete: '1', // iDEAL
|
|
98
|
+
Description: 'Test payment',
|
|
99
|
+
PushURL: '',
|
|
100
|
+
PushURLFailure: '',
|
|
101
|
+
ReturnURL: 'https://stamhoofd.be',
|
|
102
|
+
ReturnURLCancel: 'https://stamhoofd.be',
|
|
103
|
+
ReturnURLError: 'https://stamhoofd.be',
|
|
104
|
+
ReturnURLReject: 'https://stamhoofd.be',
|
|
105
|
+
};
|
|
107
106
|
|
|
108
107
|
try {
|
|
109
|
-
const response = await this.request(
|
|
110
|
-
const key = response[
|
|
108
|
+
const response = await this.request('POST', '/json/Transaction', data);
|
|
109
|
+
const key = response['Key'];
|
|
111
110
|
|
|
112
111
|
if (!key) {
|
|
113
|
-
return false
|
|
112
|
+
return false;
|
|
114
113
|
}
|
|
115
|
-
const status = this.getStatusFromResponse(response)
|
|
114
|
+
const status = this.getStatusFromResponse(response);
|
|
116
115
|
|
|
117
|
-
return status === PaymentStatus.Pending || status === PaymentStatus.Created || status === PaymentStatus.Succeeded
|
|
118
|
-
}
|
|
119
|
-
|
|
116
|
+
return status === PaymentStatus.Pending || status === PaymentStatus.Created || status === PaymentStatus.Succeeded;
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
console.error(e);
|
|
120
120
|
}
|
|
121
|
-
return false
|
|
121
|
+
return false;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
async createPayment(payment: Payment, ip: string, description: string, returnUrl: string, exchangeUrl: string): Promise<string | null> {
|
|
@@ -127,153 +127,153 @@ export class BuckarooHelper {
|
|
|
127
127
|
switch (payment.method) {
|
|
128
128
|
case PaymentMethod.iDEAL: {
|
|
129
129
|
service = {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
Name: 'ideal',
|
|
131
|
+
Action: 'Pay',
|
|
132
|
+
Parameters: [],
|
|
133
133
|
};
|
|
134
134
|
break;
|
|
135
135
|
}
|
|
136
136
|
case PaymentMethod.CreditCard: {
|
|
137
|
-
service ={
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
service = {
|
|
138
|
+
Name: 'mastercard',
|
|
139
|
+
Action: 'Pay',
|
|
140
140
|
};
|
|
141
141
|
break;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
case PaymentMethod.Bancontact: {
|
|
145
145
|
service = {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
Name: 'bancontactmrcash',
|
|
147
|
+
Action: 'Pay',
|
|
148
|
+
Parameters: [
|
|
149
149
|
{
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
]
|
|
150
|
+
Name: 'savetoken',
|
|
151
|
+
Value: 'false',
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
154
|
};
|
|
155
155
|
break;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
case PaymentMethod.Payconiq: {
|
|
159
159
|
service = {
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
Name: 'payconiq',
|
|
161
|
+
Action: 'Pay',
|
|
162
162
|
};
|
|
163
163
|
break;
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
|
|
166
|
+
|
|
167
167
|
const data = {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
168
|
+
Currency: 'EUR',
|
|
169
|
+
AmountDebit: (payment.price / 100).toFixed(2),
|
|
170
|
+
Invoice: 'ID ' + payment.id,
|
|
171
|
+
ClientIP: {
|
|
172
|
+
Type: 0, // 0 = ipv4, 1 = ipv6
|
|
173
|
+
Address: ip,
|
|
174
174
|
},
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
service
|
|
178
|
-
]
|
|
175
|
+
Services: {
|
|
176
|
+
ServiceList: [
|
|
177
|
+
service,
|
|
178
|
+
],
|
|
179
179
|
},
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
180
|
+
ContinueOnIncomplete: '1', // iDEAL
|
|
181
|
+
Description: description,
|
|
182
|
+
PushURL: exchangeUrl,
|
|
183
|
+
PushURLFailure: exchangeUrl,
|
|
184
|
+
ReturnURL: returnUrl,
|
|
185
|
+
ReturnURLCancel: returnUrl,
|
|
186
|
+
ReturnURLError: returnUrl,
|
|
187
|
+
ReturnURLReject: returnUrl,
|
|
188
|
+
};
|
|
189
189
|
|
|
190
190
|
try {
|
|
191
|
-
const response = await this.request(
|
|
192
|
-
const key = response[
|
|
191
|
+
const response = await this.request('POST', '/json/Transaction', data);
|
|
192
|
+
const key = response['Key'];
|
|
193
193
|
|
|
194
194
|
if (!key) {
|
|
195
|
-
throw new Error(
|
|
195
|
+
throw new Error('Failed to create payment, missing key');
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
payment.status = this.getStatusFromResponse(response)
|
|
198
|
+
payment.status = this.getStatusFromResponse(response);
|
|
199
199
|
|
|
200
200
|
// Save payment
|
|
201
|
-
const dbPayment = new BuckarooPayment()
|
|
202
|
-
dbPayment.paymentId = payment.id
|
|
203
|
-
dbPayment.transactionKey = key
|
|
201
|
+
const dbPayment = new BuckarooPayment();
|
|
202
|
+
dbPayment.paymentId = payment.id;
|
|
203
|
+
dbPayment.transactionKey = key;
|
|
204
204
|
await dbPayment.save();
|
|
205
205
|
|
|
206
|
-
return response[
|
|
207
|
-
}
|
|
208
|
-
|
|
206
|
+
return response['RequiredAction']?.['RedirectURL'] ?? null;
|
|
207
|
+
}
|
|
208
|
+
catch (e) {
|
|
209
|
+
console.error(e);
|
|
209
210
|
throw new SimpleError({
|
|
210
|
-
code:
|
|
211
|
-
message:
|
|
212
|
-
human:
|
|
213
|
-
})
|
|
211
|
+
code: 'buckaroo_error',
|
|
212
|
+
message: 'Failed to create payment',
|
|
213
|
+
human: 'Er ging iets mis bij het starten van de betaling. Herlaad de pagina en probeer het opnieuw.',
|
|
214
|
+
});
|
|
214
215
|
}
|
|
215
|
-
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
private getStatusFromResponse(data: any) {
|
|
219
|
-
const status: string = data[
|
|
220
|
-
if (status ===
|
|
221
|
-
return PaymentStatus.Succeeded
|
|
219
|
+
const status: string = data['Status']?.['Code']?.['Code']?.toString() ?? '';
|
|
220
|
+
if (status === '190') {
|
|
221
|
+
return PaymentStatus.Succeeded;
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
if ([
|
|
225
|
-
return PaymentStatus.Failed
|
|
224
|
+
if (['490', '491', '492', '890', '891', '690'].includes(status)) {
|
|
225
|
+
return PaymentStatus.Failed;
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
if ([
|
|
228
|
+
if (['790'].includes(status)) {
|
|
229
229
|
// Pending input
|
|
230
|
-
return PaymentStatus.Created
|
|
230
|
+
return PaymentStatus.Created;
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
-
if ([
|
|
233
|
+
if (['791', '792'].includes(status)) {
|
|
234
234
|
// Pending input
|
|
235
|
-
return PaymentStatus.Pending
|
|
235
|
+
return PaymentStatus.Pending;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
console.warn(
|
|
239
|
-
return PaymentStatus.Pending
|
|
238
|
+
console.warn('Unknown buckaroo status: ' + status + ' for ', data);
|
|
239
|
+
return PaymentStatus.Pending;
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
/**
|
|
243
243
|
* Get the status of a payment
|
|
244
244
|
*/
|
|
245
245
|
async getStatus(payment: Payment) {
|
|
246
|
-
const buckarooPayments = await BuckarooPayment.where({ paymentId: payment.id}, { limit: 1 })
|
|
247
|
-
if (buckarooPayments.length
|
|
248
|
-
throw new Error(
|
|
246
|
+
const buckarooPayments = await BuckarooPayment.where({ paymentId: payment.id }, { limit: 1 });
|
|
247
|
+
if (buckarooPayments.length !== 1) {
|
|
248
|
+
throw new Error('Failed to find Buckaroo payment for payment ' + payment.id);
|
|
249
249
|
}
|
|
250
|
-
const buckarooPayment = buckarooPayments[0]
|
|
251
|
-
|
|
250
|
+
const buckarooPayment = buckarooPayments[0];
|
|
251
|
+
|
|
252
252
|
// Send request
|
|
253
|
-
const response = await this.request(
|
|
254
|
-
const parameters = response[
|
|
253
|
+
const response = await this.request('GET', '/json/transaction/status/' + buckarooPayment.transactionKey, undefined);
|
|
254
|
+
const parameters = response['Services']?.[0]?.['Parameters'];
|
|
255
255
|
|
|
256
256
|
if (parameters && Array.isArray(parameters)) {
|
|
257
|
-
const iban = parameters.find(p => p.Name.toLowerCase() ===
|
|
257
|
+
const iban = parameters.find(p => p.Name.toLowerCase() === 'customeriban')?.Value;
|
|
258
258
|
|
|
259
259
|
if (iban) {
|
|
260
|
-
payment.iban = iban
|
|
260
|
+
payment.iban = iban;
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
-
const name = parameters.find(p => p.Name.toLowerCase() ===
|
|
263
|
+
const name = parameters.find(p => p.Name.toLowerCase() === 'customeraccountname')?.Value;
|
|
264
264
|
|
|
265
265
|
if (name) {
|
|
266
|
-
payment.ibanName = name
|
|
266
|
+
payment.ibanName = name;
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
const name = response[
|
|
270
|
+
const name = response['CustomerName'];
|
|
271
271
|
|
|
272
272
|
if (name) {
|
|
273
|
-
payment.ibanName = name
|
|
273
|
+
payment.ibanName = name;
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
// Read status
|
|
277
|
-
return this.getStatusFromResponse(response)
|
|
277
|
+
return this.getStatusFromResponse(response);
|
|
278
278
|
}
|
|
279
|
-
}
|
|
279
|
+
}
|