Skip to content

Commit ddfd4ed

Browse files
add dintero express checkout
1 parent 5280d73 commit ddfd4ed

File tree

3 files changed

+87
-23
lines changed

3 files changed

+87
-23
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@crystallize/node-service-api-request-handlers",
33
"license": "MIT",
4-
"version": "4.1.0",
4+
"version": "4.2.0",
55
"author": "Crystallize <[email protected]> (https://crystallize.com)",
66
"contributors": [
77
"Sébastien Morel <[email protected]>",

src/payments/dintero/handlers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export async function handleDinteroPaymentSessionPayload(
99

1010
const authToken = await fetchDinteroAuthToken(args.credentials);
1111

12+
const expressCheckoutObject = args.express?.enabled ? { express: args.express.expressCheckoutOptions } : {};
13+
1214
const response = await fetch('https://checkout.dintero.com/v1/sessions-profile', {
1315
method: 'POST',
1416
headers: {
@@ -46,6 +48,7 @@ export async function handleDinteroPaymentSessionPayload(
4648
customer: {
4749
email: args?.customer?.email ?? '',
4850
},
51+
...expressCheckoutObject,
4952
}),
5053
}).then((res) => res.json());
5154

src/payments/dintero/types.ts

Lines changed: 83 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,22 @@ export const dinteroPaymentPayload = z
99

1010
export type DinteroPaymentPayload = z.infer<typeof dinteroPaymentPayload>;
1111

12-
export type DinteroAddress = {
13-
first_name?: string;
14-
last_name?: string;
15-
address_line?: string;
16-
address_line_2?: string;
17-
co_address?: string;
18-
business_name?: string;
19-
postal_code?: string;
20-
postal_place?: string;
21-
country?: string;
22-
phone_number?: string;
23-
email?: string;
24-
latitude?: number;
25-
longitude?: number;
26-
comment?: string;
27-
organization_number?: string;
28-
organization_type?: string;
29-
customer_reference?: string;
30-
cost_center?: string;
31-
};
32-
3312
export type DinteroCreateSessionArguments = {
3413
credentials: DinteroCredentials;
3514
fetchCart: () => Promise<Cart>;
3615
returnUrl: string;
3716
callbackUrl: string;
38-
otherPaymentArguments?: any;
3917
customer?: {
4018
email?: string;
4119
phone?: string;
4220
shippingAddress?: DinteroAddress;
4321
billingAddress?: DinteroAddress;
4422
};
23+
express?: {
24+
enabled: boolean;
25+
expressCheckoutOptions: ExpressShipping;
26+
};
27+
otherPaymentArguments?: any;
4528
};
4629

4730
export type DinteroCredentials = {
@@ -58,3 +41,81 @@ export type DinteroPaymentVerificationArguments = {
5841
credentials: DinteroCredentials;
5942
handleEvent: (eventName: string, event: any) => Promise<any>;
6043
};
44+
45+
export type DinteroAddress = {
46+
first_name?: string;
47+
last_name?: string;
48+
address_line?: string;
49+
address_line_2?: string;
50+
co_address?: string;
51+
business_name?: string;
52+
postal_code?: string;
53+
postal_place?: string;
54+
country?: string;
55+
phone_number?: string;
56+
email?: string;
57+
latitude?: number;
58+
longitude?: number;
59+
comment?: string;
60+
organization_number?: string;
61+
organization_type?: string;
62+
customer_reference?: string;
63+
cost_center?: string;
64+
};
65+
66+
type Eta = {
67+
starts_at: string;
68+
ends_at: string;
69+
};
70+
71+
type TimeSlot = {
72+
starts_at: string;
73+
ends_at: string;
74+
};
75+
76+
type Metadata = {
77+
operator_dest: string;
78+
number_x: number;
79+
};
80+
81+
type Details = {
82+
label: string;
83+
value: string;
84+
};
85+
86+
type EnvironmentalData = {
87+
description: string;
88+
details: Details[];
89+
};
90+
91+
type ShippingOption = {
92+
id: string;
93+
line_id: string;
94+
countries?: string[];
95+
amount: number;
96+
vat_amount?: number;
97+
vat?: number;
98+
title: string;
99+
description?: string;
100+
delivery_method?: 'delivery' | 'pick_up' | 'unspecified' | 'none';
101+
operator: string;
102+
operator_product_id?: string;
103+
eta?: Eta;
104+
time_slot?: TimeSlot;
105+
pick_up_address?: DinteroAddress;
106+
metadata?: Metadata;
107+
environmental_data?: EnvironmentalData;
108+
};
109+
110+
type DiscountCodes = {
111+
max_count: number;
112+
callback_url: string;
113+
};
114+
115+
type ExpressShipping = {
116+
shipping_options: ShippingOption[];
117+
shipping_mode?: string;
118+
discount_codes?: DiscountCodes;
119+
shipping_address_callback_url?: string;
120+
customer_types?: ('b2c' | 'b2b')[];
121+
};

0 commit comments

Comments
 (0)