Skip to content

Commit 468fd5f

Browse files
authored
Merge pull request #21 from codemash-io/version1
feat(payments): get applicable discounts
2 parents 49f7bfd + 44c8983 commit 468fd5f

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/components/payments.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export async function getOrders({
6464

6565
export async function createOrder({
6666
secretKey,
67+
coupons,
6768
accountId,
6869
orderSchemaId,
6970
userId,
@@ -84,6 +85,7 @@ export async function createOrder({
8485
'Content-Type': 'application/json',
8586
},
8687
body: JSON.stringify({
88+
coupons,
8789
accountId,
8890
orderSchemaId,
8991
userId,
@@ -495,3 +497,63 @@ export async function cancelSubscription({secretKey, id, customerId}) {
495497

496498
return response;
497499
}
500+
501+
export async function getApplicableCoupons({
502+
secretKey,
503+
codes,
504+
orderSchemaId,
505+
userId,
506+
lines,
507+
asGuest,
508+
}) {
509+
const response = await server.loadJson(
510+
`${Config.apiUrl}${Endpoints.PROJECT.PAYMENTS.DISCOUNTS.GET_APPLICABLE_COUPONS}`,
511+
{
512+
method: 'POST',
513+
headers: {
514+
'X-CM-ProjectId': Config.projectId,
515+
Authorization: `Bearer ${secretKey || Config.secretKey}`,
516+
Accept: 'application/json',
517+
'Content-Type': 'application/json',
518+
},
519+
body: JSON.stringify({
520+
codes,
521+
orderSchemaId,
522+
userId,
523+
lines,
524+
asGuest,
525+
}),
526+
}
527+
);
528+
529+
return response;
530+
}
531+
532+
export async function getApplicableDiscounts({
533+
secretKey,
534+
orderSchemaId,
535+
userId,
536+
lines,
537+
asGuest,
538+
}) {
539+
const response = await server.loadJson(
540+
`${Config.apiUrl}${Endpoints.PROJECT.PAYMENTS.DISCOUNTS.GET_APPLICABLE_DISCOUNTS}`,
541+
{
542+
method: 'POST',
543+
headers: {
544+
'X-CM-ProjectId': Config.projectId,
545+
Authorization: `Bearer ${secretKey || Config.secretKey}`,
546+
Accept: 'application/json',
547+
'Content-Type': 'application/json',
548+
},
549+
body: JSON.stringify({
550+
orderSchemaId,
551+
userId,
552+
lines,
553+
asGuest,
554+
}),
555+
}
556+
);
557+
558+
return response;
559+
}

src/routes.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ export const CONFIG = {
124124
`/v2/payments/orders/${orderId}/paysera/pay`,
125125
CREATE_STRIPE: (orderId) => `/v2/payments/orders/${orderId}/stripe/pay`,
126126
},
127+
DISCOUNTS: {
128+
CREATE_DISCOUNT: '/v2/payments/discounts',
129+
GET_APPLICABLE_COUPONS: '/v2/payments/discounts/coupon',
130+
GET_APPLICABLE_DISCOUNTS: '/v2/payments/discounts/applicable',
131+
DELETE_DISCOUNT: (id) => `/v2/payments/discounts/${id}`,
132+
UPDATE_DISCOUNT: (id) => `/v2/payments/discounts/${id}`,
133+
},
127134
CUSTOMERS: {
128135
CREATE: '/v2/payments/customers',
129136
GET: (customerId) => `/v2/payments/customers/${customerId}`,

0 commit comments

Comments
 (0)