-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
shipping-providers.ts
142 lines (137 loc) · 3.92 KB
/
shipping-providers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* Internal dependencies
*/
import {
EnviaSinglePartner,
SkydropxSinglePartner,
SendcloudSinglePartner,
PacklinkSinglePartner,
ShipStationSinglePartner,
PacklinkDualPartner,
SendcloudDualPartner,
ShipStationDualPartner,
WooCommerceShippingSinglePartner,
} from './partners';
// Order is respected, left to right in the UI
const shippingProviders = {
AU: {
shipping_providers: [ 'ShipStation' ] as const,
},
MX: {
// using name instead of directly referencing the component because we want to send this over the API in the near future
shipping_providers: [ 'Skydropx' ] as const,
},
CA: {
shipping_providers: [ 'ShipStation' ] as const,
},
CO: {
shipping_providers: [ 'Skydropx' ] as const,
},
CL: {
shipping_providers: [ 'Envia' ] as const,
},
AR: {
shipping_providers: [ 'Envia' ] as const,
},
PE: {
shipping_providers: [ 'Envia' ] as const,
},
BR: {
shipping_providers: [ 'Envia' ] as const,
},
UY: {
shipping_providers: [ 'Envia' ] as const,
},
GT: {
shipping_providers: [ 'Envia' ] as const,
},
NL: {
shipping_providers: [ 'Sendcloud' ] as const,
},
AT: {
shipping_providers: [ 'Sendcloud' ] as const,
},
BE: {
shipping_providers: [ 'Sendcloud' ] as const,
},
FR: {
shipping_providers: [ 'Sendcloud', 'Packlink' ] as const,
},
DE: {
shipping_providers: [ 'Sendcloud', 'Packlink' ] as const,
},
ES: {
shipping_providers: [ 'Packlink', 'Sendcloud' ] as const,
},
IT: {
shipping_providers: [ 'Packlink', 'Sendcloud' ] as const,
},
GB: {
shipping_providers: [ 'Sendcloud', 'ShipStation' ] as const,
},
US: {
shipping_providers: [ 'WooCommerceShipping' ] as const,
},
};
const providers = {
Envia: {
name: 'Envia' as const,
url: 'https://woocommerce.com/products/envia-shipping-and-fulfillment/', // no plugin yet so we link to the product page
'single-partner-layout': EnviaSinglePartner,
},
Skydropx: {
name: 'Skydropx' as const,
slug: 'skydropx-cotizador-y-envios', // https://wordpress.org/plugins/skydropx-cotizador-y-envios/
url: 'https://wordpress.org/plugins/skydropx-cotizador-y-envios/',
'single-partner-layout': SkydropxSinglePartner,
},
Sendcloud: {
name: 'Sendcloud' as const,
slug: 'sendcloud-shipping', // https://wordpress.org/plugins/sendcloud-shipping/
url: 'https://wordpress.org/plugins/sendcloud-shipping/',
'single-partner-layout': SendcloudSinglePartner,
'dual-partner-layout': SendcloudDualPartner,
},
Packlink: {
name: 'Packlink' as const,
slug: 'packlink-pro-shipping', // https://wordpress.org/plugins/packlink-pro-shipping/
url: 'https://wordpress.org/plugins/packlink-pro-shipping/',
'single-partner-layout': PacklinkSinglePartner,
'dual-partner-layout': PacklinkDualPartner,
},
ShipStation: {
name: 'ShipStation' as const,
slug: 'woocommerce-shipstation-integration', // https://wordpress.org/plugins/woocommerce-shipstation-integration/
url: 'https://wordpress.org/plugins/woocommerce-shipstation-integration/',
'single-partner-layout': ShipStationSinglePartner,
'dual-partner-layout': ShipStationDualPartner,
},
WooCommerceShipping: {
name: 'WooCommerce Shipping' as const,
slug: 'woocommerce-services', // https://wordpress.org/plugins/woocommerce-services/
url: 'https://woocommerce.com/products/shipping',
dependencies: 'jetpack',
'single-partner-layout': WooCommerceShippingSinglePartner,
},
} as const;
/**
* Gets the components for the shipping providers for a given country
*
* @param countryCode One of the countries above
* @return Either a single partner component or an array containing two partner components
*/
export const getShippingProviders = (
countryCode: keyof typeof shippingProviders
) => {
const countryProviders =
shippingProviders[ countryCode ]?.shipping_providers;
if ( ! countryProviders ) {
return [];
}
return countryProviders.length === 1
? [ providers[ countryProviders[ 0 ] ] ]
: [
providers[ countryProviders[ 0 ] ],
providers[ countryProviders[ 1 ] ],
];
};