chore(docs): added eslint to lint documentation code blocks (#2920)
* docs: added rule for code length * chore: fixes based on vale errors * changed to use eslint * fixes using eslint * added github action for documentation eslint * changed allowed max-length * fixed incorrect heading level * removed comment
This commit is contained in:
@@ -60,8 +60,8 @@ medusa.customers.create({
|
||||
last_name,
|
||||
})
|
||||
.then(({ customer }) => {
|
||||
console.log(customer.id);
|
||||
});
|
||||
console.log(customer.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -69,19 +69,19 @@ medusa.customers.create({
|
||||
|
||||
```ts
|
||||
fetch(`<SERVER_URL>/store/customers`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify({
|
||||
email,
|
||||
password,
|
||||
first_name,
|
||||
last_name,
|
||||
})
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ customer }) => {
|
||||
console.log(customer.id);
|
||||
});
|
||||
console.log(customer.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -112,11 +112,11 @@ You can log in a customer into your store by sending a request to the [Customer
|
||||
```ts
|
||||
medusa.auth.authenticate({
|
||||
email,
|
||||
password
|
||||
password,
|
||||
})
|
||||
.then(({ customer }) => {
|
||||
console.log(customer.id);
|
||||
});
|
||||
console.log(customer.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -124,17 +124,17 @@ medusa.auth.authenticate({
|
||||
|
||||
```ts
|
||||
fetch(`<SERVER_URL>/store/auth`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify({
|
||||
email,
|
||||
password
|
||||
})
|
||||
password,
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ customer }) => {
|
||||
console.log(customer.id);
|
||||
});
|
||||
console.log(customer.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -158,8 +158,8 @@ You can log out a customer by sending a request to the [Customer Logout](/api/st
|
||||
```ts
|
||||
medusa.auth.deleteSession()
|
||||
.then(() => {
|
||||
//success
|
||||
});
|
||||
// success
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -167,12 +167,12 @@ medusa.auth.deleteSession()
|
||||
|
||||
```ts
|
||||
fetch(`<SERVER_URL>/store/auth`, {
|
||||
method: 'DELETE',
|
||||
credentials: 'include'
|
||||
method: "DELETE",
|
||||
credentials: "include",
|
||||
})
|
||||
.then(() => {
|
||||
//success
|
||||
});
|
||||
// success
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -197,7 +197,7 @@ You can request to reset a customer’s password by sending a request to the [Re
|
||||
|
||||
```ts
|
||||
medusa.customers.generatePasswordToken({
|
||||
email
|
||||
email,
|
||||
})
|
||||
.then(() => {
|
||||
// successful
|
||||
@@ -212,11 +212,11 @@ medusa.customers.generatePasswordToken({
|
||||
|
||||
```ts
|
||||
fetch(`<SERVER_URL>/store/customers/password-token`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify({
|
||||
email
|
||||
})
|
||||
email,
|
||||
}),
|
||||
})
|
||||
.then(() => {
|
||||
// successful
|
||||
@@ -252,11 +252,11 @@ You can then reset the customer’s password to the new password they enter by s
|
||||
medusa.customers.resetPassword({
|
||||
email,
|
||||
password,
|
||||
token
|
||||
token,
|
||||
})
|
||||
.then(({ customer }) => {
|
||||
console.log(customer.id);
|
||||
});
|
||||
console.log(customer.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -264,18 +264,18 @@ medusa.customers.resetPassword({
|
||||
|
||||
```ts
|
||||
fetch(`<SERVER_URL>/store/customers/password-reset`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify({
|
||||
email,
|
||||
password,
|
||||
token
|
||||
})
|
||||
token,
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ customer }) => {
|
||||
console.log(customer.id);
|
||||
});
|
||||
console.log(customer.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -302,11 +302,11 @@ You can edit a customer’s info using the [Update Customer](/api/store/#tag/Cus
|
||||
|
||||
```ts
|
||||
medusa.customers.update({
|
||||
first_name
|
||||
first_name,
|
||||
})
|
||||
.then(({ customer }) => {
|
||||
console.log(customer.id);
|
||||
});
|
||||
console.log(customer.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -314,16 +314,16 @@ medusa.customers.update({
|
||||
|
||||
```ts
|
||||
fetch(`<SERVER_URL>/store/customers/me`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify({
|
||||
first_name
|
||||
})
|
||||
first_name,
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ customer }) => {
|
||||
console.log(customer.id);
|
||||
});
|
||||
console.log(customer.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -365,12 +365,12 @@ medusa.customers.addresses.addAddress({
|
||||
company,
|
||||
address_2,
|
||||
province,
|
||||
metadata
|
||||
}
|
||||
metadata,
|
||||
},
|
||||
})
|
||||
.then(({ customer }) => {
|
||||
console.log(customer.id);
|
||||
});
|
||||
console.log(customer.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -378,8 +378,8 @@ medusa.customers.addresses.addAddress({
|
||||
|
||||
```ts
|
||||
fetch(`<SERVER_URL>/store/customers/me/addresses`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify({
|
||||
address: {
|
||||
first_name,
|
||||
@@ -392,14 +392,14 @@ fetch(`<SERVER_URL>/store/customers/me/addresses`, {
|
||||
company,
|
||||
address_2,
|
||||
province,
|
||||
metadata
|
||||
}
|
||||
})
|
||||
metadata,
|
||||
},
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ customer }) => {
|
||||
console.log(customer.id);
|
||||
});
|
||||
console.log(customer.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -427,11 +427,11 @@ You can edit a customer’s shipping address using the [Update a Shipping Addres
|
||||
|
||||
```ts
|
||||
medusa.customers.addresses.updateAddress(addressId, {
|
||||
first_name
|
||||
first_name,
|
||||
})
|
||||
.then(({ customer }) => {
|
||||
console.log(customer.id);
|
||||
});
|
||||
console.log(customer.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -439,16 +439,16 @@ medusa.customers.addresses.updateAddress(addressId, {
|
||||
|
||||
```ts
|
||||
fetch(`<SERVER_URL>/store/customers/me/addresses/${addressId}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify({
|
||||
first_name
|
||||
})
|
||||
first_name,
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ customer }) => {
|
||||
console.log(customer.id);
|
||||
});
|
||||
console.log(customer.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -468,8 +468,8 @@ You can delete a shipping address by sending a request to the [Delete an Address
|
||||
```ts
|
||||
medusa.customers.addresses.deleteAddress(addressId)
|
||||
.then(({ customer }) => {
|
||||
console.log(customer.id);
|
||||
});
|
||||
console.log(customer.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -477,13 +477,13 @@ medusa.customers.addresses.deleteAddress(addressId)
|
||||
|
||||
```ts
|
||||
fetch(`<SERVER_URL>/store/customers/me/addresses/${addressId}`, {
|
||||
method: 'DELETE',
|
||||
credentials: 'include'
|
||||
method: "DELETE",
|
||||
credentials: "include",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ customer }) => {
|
||||
console.log(customer.id);
|
||||
});
|
||||
console.log(customer.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -505,8 +505,8 @@ You can retrieve a customer’s orders by sending a request to the [List Orders]
|
||||
```ts
|
||||
medusa.customers.listOrders()
|
||||
.then(({ orders, limit, offset, count }) => {
|
||||
console.log(orders);
|
||||
});
|
||||
console.log(orders)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -514,12 +514,12 @@ medusa.customers.listOrders()
|
||||
|
||||
```ts
|
||||
fetch(`<SERVER_URL>/store/customers/me/orders`, {
|
||||
credentials: 'include'
|
||||
credentials: "include",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ orders, limit, offset, count }) => {
|
||||
console.log(orders);
|
||||
});
|
||||
console.log(orders)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
@@ -78,9 +78,9 @@ You can retrieve a single order edit by its ID by sending a request to the [Get
|
||||
```ts
|
||||
medusa.orderEdits.retrieve(orderEditId)
|
||||
.then(({ order_edit }) => {
|
||||
console.log(order_edit.changes);
|
||||
//show changed items to the customer
|
||||
});
|
||||
console.log(order_edit.changes)
|
||||
// show changed items to the customer
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -90,9 +90,9 @@ medusa.orderEdits.retrieve(orderEditId)
|
||||
fetch(`<SERVER_URL>/store/order-edits/${orderEditId}`)
|
||||
.then((response) => response.json())
|
||||
.then(({ order_edit }) => {
|
||||
console.log(order_edit.changes);
|
||||
//show changed items to the customer
|
||||
});
|
||||
console.log(order_edit.changes)
|
||||
// show changed items to the customer
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -116,6 +116,8 @@ You can learn more about what fields to expect in the [API reference](/api/store
|
||||
|
||||
All data about changes to the original order’s items can be found in `order_edit.changes`. `changes` is an array of item changes. Each item change includes the following fields:
|
||||
|
||||
<!-- eslint-skip -->
|
||||
|
||||
```ts
|
||||
{
|
||||
type: string,
|
||||
@@ -134,14 +136,22 @@ Here’s an example of how you can use this data to show the customer the reques
|
||||
|
||||
```jsx
|
||||
<ul>
|
||||
{orderEdit.changes.map(itemChange => (
|
||||
{orderEdit.changes.map((itemChange) => (
|
||||
<li key={itemChange.id}>
|
||||
<strong>{itemChange.line_item ? itemChange.line_item.title : itemChange.original_line_item.title}</strong>
|
||||
{itemChange.type === 'added' && <span>New Item</span>}
|
||||
{itemChange.type === 'removed' && <span>Removed Item</span>}
|
||||
{itemChange.type === 'edited' &&
|
||||
<strong>
|
||||
{
|
||||
itemChange.line_item ?
|
||||
itemChange.line_item.title :
|
||||
itemChange.original_line_item.title
|
||||
}
|
||||
</strong>
|
||||
{itemChange.type === "added" && <span>New Item</span>}
|
||||
{itemChange.type === "removed" && <span>Removed Item</span>}
|
||||
{itemChange.type === "edited" &&
|
||||
<span>
|
||||
Edited Item. Old Quantity: {itemChange.original_line_item.quantity}. New Quantity: {itemChange.line_item.quantity}
|
||||
Edited Item
|
||||
Old Quantity: {itemChange.original_line_item.quantity}
|
||||
New Quantity: {itemChange.line_item.quantity}
|
||||
</span>}
|
||||
</li>
|
||||
))}
|
||||
@@ -178,31 +188,34 @@ If `difference_due` is greater than 0, then additional payment from the customer
|
||||
|
||||
```ts
|
||||
medusa.paymentCollections.managePaymentSession(paymentCollectionId, {
|
||||
provider_id
|
||||
provider_id,
|
||||
})
|
||||
.then(({ payment_collection }) => {
|
||||
console.log(payment_collection.payment_sessions);
|
||||
});
|
||||
console.log(payment_collection.payment_sessions)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="fetch" label="Fetch API">
|
||||
|
||||
```ts
|
||||
fetch(`<SERVER_URL>/store/payment-collections/${paymentCollectionId}/sessions`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
provider_id
|
||||
})
|
||||
})
|
||||
fetch(
|
||||
`<SERVER_URL>/store/payment-collections/${paymentCollectionId}/sessions`,
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
provider_id,
|
||||
}),
|
||||
}
|
||||
)
|
||||
.then((response) => response.json())
|
||||
.then(({ payment_collection }) => {
|
||||
console.log(payment_collection.payment_sessions);
|
||||
});
|
||||
console.log(payment_collection.payment_sessions)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -215,24 +228,29 @@ fetch(`<SERVER_URL>/store/payment-collections/${paymentCollectionId}/sessions`,
|
||||
<TabItem value="client" label="Medusa JS Client" default>
|
||||
|
||||
```ts
|
||||
medusa.paymentCollection.authorizePaymentSession(paymentCollectionId, paymentSessionId)
|
||||
medusa.paymentCollection
|
||||
.authorizePaymentSession(paymentCollectionId, paymentSessionId)
|
||||
.then(({ payment_session }) => {
|
||||
console.log(payment_session.id);
|
||||
});
|
||||
console.log(payment_session.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="fetch" label="Fetch API">
|
||||
|
||||
```ts
|
||||
fetch(`<SERVER_URL>/store/payment-collection/${paymentCollectionId}/sessions/${paymentSessionId}/authorize`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
})
|
||||
fetch(
|
||||
`<SERVER_URL>/store/payment-collection/${paymentCollectionId}` +
|
||||
`/sessions/${paymentSessionId}/authorize`,
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
}
|
||||
)
|
||||
.then((response) => response.json())
|
||||
.then(({ payment_session }) => {
|
||||
console.log(payment_session.id);
|
||||
});
|
||||
console.log(payment_session.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -252,8 +270,8 @@ To confirm and complete the order edit, send a request to the [Complete Order Ed
|
||||
```ts
|
||||
medusa.orderEdits.complete(orderEditId)
|
||||
.then(({ order_edit }) => {
|
||||
console.log(order_edit.confirmed_at);
|
||||
});
|
||||
console.log(order_edit.confirmed_at)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -261,13 +279,13 @@ medusa.orderEdits.complete(orderEditId)
|
||||
|
||||
```ts
|
||||
fetch(`<SERVER_URL>/store/order-edits/${orderEditId}/complete`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ order_edit }) => {
|
||||
console.log(order_edit.confirmed_at);
|
||||
});
|
||||
console.log(order_edit.confirmed_at)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -296,11 +314,11 @@ If the customer wants to decline the Order Edit, you can do that by sending a re
|
||||
|
||||
```ts
|
||||
medusa.orderEdits.decline(orderEditId, {
|
||||
decline_reason: 'I am not satisfied'
|
||||
decline_reason: "I am not satisfied",
|
||||
})
|
||||
.then(({ order_edit }) => {
|
||||
console.log(order_edit.declined_at);
|
||||
});
|
||||
console.log(order_edit.declined_at)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -308,19 +326,19 @@ medusa.orderEdits.decline(orderEditId, {
|
||||
|
||||
```ts
|
||||
fetch(`<SERVER_URL>/store/order-edits/${orderEditId}/decline`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
decline_reason: 'I am not satisfied'
|
||||
})
|
||||
decline_reason: "I am not satisfied",
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ order_edit }) => {
|
||||
console.log(order_edit.declined_at);
|
||||
});
|
||||
console.log(order_edit.declined_at)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
@@ -64,11 +64,11 @@ medusa.carts.update(cartId, {
|
||||
country_code,
|
||||
province,
|
||||
postal_code,
|
||||
phone
|
||||
phone,
|
||||
},
|
||||
})
|
||||
.then(({ cart }) => {
|
||||
console.log(cart.shipping_address);
|
||||
console.log(cart.shipping_address)
|
||||
})
|
||||
```
|
||||
|
||||
@@ -77,8 +77,8 @@ medusa.carts.update(cartId, {
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify({
|
||||
shipping_address: {
|
||||
company,
|
||||
@@ -90,17 +90,17 @@ fetch(`<SERVER_URL>/store/carts/${cartId}`, {
|
||||
country_code,
|
||||
province,
|
||||
postal_code,
|
||||
phone
|
||||
phone,
|
||||
},
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ cart }) => {
|
||||
console.log(cart.shipping_address);
|
||||
});
|
||||
console.log(cart.shipping_address)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -124,7 +124,7 @@ You can retrieve the list of shipping options by sending a `GET` request to the
|
||||
```jsx
|
||||
medusa.shippingOptions.listCartOptions(cartId)
|
||||
.then(({ shipping_options }) => {
|
||||
console.log(shipping_options.length);
|
||||
console.log(shipping_options.length)
|
||||
})
|
||||
```
|
||||
|
||||
@@ -133,11 +133,11 @@ medusa.shippingOptions.listCartOptions(cartId)
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/shipping-options/${cartId}`, {
|
||||
credentials: 'include',
|
||||
credentials: "include",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ shipping_options }) => {
|
||||
console.log(shipping_options.length);
|
||||
console.log(shipping_options.length)
|
||||
})
|
||||
```
|
||||
|
||||
@@ -155,7 +155,7 @@ Once the customer chooses one of the available shipping options, send a `POST` r
|
||||
|
||||
```jsx
|
||||
medusa.carts.addShippingMethod(cartId, {
|
||||
option_id: shippingOptionId //the ID of the selected option
|
||||
option_id: shippingOptionId, // the ID of the selected option
|
||||
})
|
||||
.then(({ cart }) => {
|
||||
console.log(cart.shipping_methods)
|
||||
@@ -167,14 +167,14 @@ medusa.carts.addShippingMethod(cartId, {
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}/shipping-methods`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify({
|
||||
option_id: shippingOptionId //the ID of the selected option
|
||||
option_id: shippingOptionId, // the ID of the selected option
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ cart }) => {
|
||||
@@ -216,8 +216,8 @@ medusa.carts.createPaymentSessions(cartId)
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}/payment-sessions`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ cart }) => {
|
||||
@@ -239,7 +239,8 @@ When the customer chooses the payment provider they want to complete purchase wi
|
||||
|
||||
```jsx
|
||||
medusa.carts.setPaymentSession(cartId, {
|
||||
provider_id: paymentProviderId // retrieved from the payment session selected by the customer
|
||||
// retrieved from the payment session selected by the customer
|
||||
provider_id: paymentProviderId,
|
||||
})
|
||||
.then(({ cart }) => {
|
||||
console.log(cart.payment_session)
|
||||
@@ -251,14 +252,15 @@ medusa.carts.setPaymentSession(cartId, {
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}/payment-session`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify({
|
||||
provider_id: paymentProviderId // retrieved from the payment session selected by the customer
|
||||
// retrieved from the payment session selected by the customer
|
||||
provider_id: paymentProviderId,
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ cart }) => {
|
||||
@@ -291,10 +293,10 @@ If you need to update that data at any point before the purchase is made, send a
|
||||
```jsx
|
||||
medusa.carts.updatePaymentSession(cartId, paymentProviderId, {
|
||||
data: {
|
||||
//pass any data you want to add in the `data` attribute
|
||||
//for example:
|
||||
"test": true
|
||||
}
|
||||
// pass any data you want to add in the `data` attribute
|
||||
// for example:
|
||||
"test": true,
|
||||
},
|
||||
})
|
||||
.then(({ cart }) => {
|
||||
console.log(cart.payment_session.data)
|
||||
@@ -304,21 +306,26 @@ medusa.carts.updatePaymentSession(cartId, paymentProviderId, {
|
||||
</TabItem>
|
||||
<TabItem value="fetch" label="Fetch API">
|
||||
|
||||
<!-- eslint-disable max-len -->
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}/payment-sessions/${paymentProviderId}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({
|
||||
data: {
|
||||
//pass any data you want to add in the `data` attribute
|
||||
//for example:
|
||||
"test": true
|
||||
}
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
fetch(
|
||||
`<SERVER_URL>/store/carts/${cartId}/payment-sessions/${paymentProviderId}`,
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify({
|
||||
data: {
|
||||
// pass any data you want to add in the `data` attribute
|
||||
// for example:
|
||||
"test": true,
|
||||
},
|
||||
}),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
})
|
||||
)
|
||||
.then((response) => response.json())
|
||||
.then(({ cart }) => {
|
||||
console.log(cart.payment_session.data)
|
||||
@@ -344,7 +351,7 @@ To complete a cart, send a `POST` request to the [Complete a Cart](/api/store/#t
|
||||
```jsx
|
||||
medusa.carts.complete(cartId)
|
||||
.then(({ type, data }) => {
|
||||
console.log(type, data);
|
||||
console.log(type, data)
|
||||
})
|
||||
```
|
||||
|
||||
@@ -353,15 +360,15 @@ medusa.carts.complete(cartId)
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}/complete`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ type, data }) => {
|
||||
console.log(type, data);
|
||||
console.log(type, data)
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ medusa.orders.claimOrders({
|
||||
})
|
||||
.catch(() => {
|
||||
// an error occurred
|
||||
});
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -90,23 +90,23 @@ medusa.orders.claimOrders({
|
||||
|
||||
```tsx
|
||||
fetch(`<SERVER_URL>/store/orders/batch/customer/token`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify({
|
||||
order_ids: [
|
||||
order_id,
|
||||
],
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
//successful
|
||||
// successful
|
||||
})
|
||||
.catch(() => {
|
||||
//display an error to the customer
|
||||
});
|
||||
// display an error to the customer
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -131,14 +131,14 @@ Then, you send a request to the Verify Claim Order endpoint:
|
||||
|
||||
```tsx
|
||||
medusa.orders.confirmRequest({
|
||||
token
|
||||
token,
|
||||
})
|
||||
.then(() => {
|
||||
// successful
|
||||
})
|
||||
.catch(() => {
|
||||
// an error occurred
|
||||
});
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -146,21 +146,21 @@ medusa.orders.confirmRequest({
|
||||
|
||||
```tsx
|
||||
fetch(`<SERVER_URL>/store/orders/customer/confirm`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify({
|
||||
token
|
||||
token,
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
//successful
|
||||
// successful
|
||||
})
|
||||
.catch(() => {
|
||||
//display an error to the customer
|
||||
});
|
||||
// display an error to the customer
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
@@ -58,17 +58,17 @@ You can add a discount to a customer’s cart by sending the [Update Cart reques
|
||||
medusa.carts.update(cartId, {
|
||||
discounts: [
|
||||
{
|
||||
code
|
||||
}
|
||||
]
|
||||
code,
|
||||
},
|
||||
],
|
||||
})
|
||||
.then(({ cart }) => {
|
||||
console.log(cart.discounts)
|
||||
})
|
||||
.catch((e) => {
|
||||
//display an error to the customer
|
||||
alert('Discount is invalid')
|
||||
});
|
||||
// display an error to the customer
|
||||
alert("Discount is invalid")
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -76,27 +76,27 @@ medusa.carts.update(cartId, {
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify({
|
||||
discounts: [
|
||||
{
|
||||
code
|
||||
}
|
||||
code,
|
||||
},
|
||||
],
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ cart }) => {
|
||||
console.log(cart.discounts);
|
||||
console.log(cart.discounts)
|
||||
})
|
||||
.catch((e) => {
|
||||
//display an error to the customer
|
||||
alert('Discount is invalid')
|
||||
});
|
||||
// display an error to the customer
|
||||
alert("Discount is invalid")
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -222,7 +222,7 @@ You can remove a discount from a customer’s cart using the [Remove Discount re
|
||||
medusa.carts.deleteDiscount(cartId, code)
|
||||
.then(({ cart }) => {
|
||||
console.log(cart.discounts)
|
||||
});
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -230,13 +230,13 @@ medusa.carts.deleteDiscount(cartId, code)
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}/discounts/${code}`, {
|
||||
method: 'DELETE',
|
||||
credentials: 'include'
|
||||
method: "DELETE",
|
||||
credentials: "include",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ cart }) => {
|
||||
console.log(cart.discounts);
|
||||
});
|
||||
console.log(cart.discounts)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
@@ -47,9 +47,9 @@ You can retrieve available regions by sending a request to the [List Regions](/a
|
||||
```tsx
|
||||
medusa.regions.list()
|
||||
.then(({ regions }) => {
|
||||
console.log(regions.length);
|
||||
//show customers available regions
|
||||
});
|
||||
console.log(regions.length)
|
||||
// show customers available regions
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -57,13 +57,13 @@ medusa.regions.list()
|
||||
|
||||
```tsx
|
||||
fetch(`<SERVER_URL>/store/regions`, {
|
||||
credentials: 'include',
|
||||
credentials: "include",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ regions }) => {
|
||||
console.log(regions.length);
|
||||
//show customers available regions
|
||||
});
|
||||
console.log(regions.length)
|
||||
// show customers available regions
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -86,12 +86,12 @@ For example:
|
||||
|
||||
```tsx
|
||||
medusa.products.list({
|
||||
region_id: regionId
|
||||
region_id: regionId,
|
||||
})
|
||||
.then(({ products, limit, offset, count }) => {
|
||||
console.log(products.length);
|
||||
//show customer the products
|
||||
});
|
||||
console.log(products.length)
|
||||
// show customer the products
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -99,13 +99,13 @@ medusa.products.list({
|
||||
|
||||
```tsx
|
||||
fetch(`<SERVER_URL>/store/products?region_id=${regionId}`, {
|
||||
credentials: 'include',
|
||||
credentials: "include",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ products, limit, offset, count }) => {
|
||||
console.log(products.length);
|
||||
//show customer the products
|
||||
});
|
||||
console.log(products.length)
|
||||
// show customer the products
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -136,11 +136,11 @@ For example:
|
||||
|
||||
```tsx
|
||||
medusa.carts.update(cartId, {
|
||||
region_id: regionId
|
||||
region_id: regionId,
|
||||
})
|
||||
.then(({ cart }) => {
|
||||
console.log(cart.id);
|
||||
});
|
||||
console.log(cart.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -148,16 +148,16 @@ medusa.carts.update(cartId, {
|
||||
|
||||
```tsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify({
|
||||
region_id: regionId
|
||||
})
|
||||
region_id: regionId,
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({ cart }) => {
|
||||
console.log(cart.id);
|
||||
});
|
||||
console.log(cart.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
@@ -39,12 +39,12 @@ To filter products by a specific sales channel, pass the `sales_channel_id` quer
|
||||
```jsx
|
||||
medusa.products.list({
|
||||
sales_channel_id: [
|
||||
salesChannelId
|
||||
]
|
||||
salesChannelId,
|
||||
],
|
||||
})
|
||||
.then(({ products, limit, offset, count }) => {
|
||||
console.log(products.length);
|
||||
});
|
||||
console.log(products.length)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -55,7 +55,7 @@ fetch(`<SERVER_URL>/store/products?sales_channel_id[0]=${salesChannelId}`)
|
||||
.then((response) => response.json())
|
||||
.then(({ products, limit, offset, count }) => {
|
||||
console.log(products.length)
|
||||
});
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -79,11 +79,11 @@ To associate a sales channel with a cart while creating it, you can pass the `sa
|
||||
|
||||
```jsx
|
||||
medusa.carts.create({
|
||||
sales_channel_id: salesChannelId
|
||||
sales_channel_id: salesChannelId,
|
||||
})
|
||||
.then(({ cart }) => {
|
||||
console.log(cart.id)
|
||||
})
|
||||
.then(({cart}) => {
|
||||
console.log(cart.id);
|
||||
});
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -91,18 +91,18 @@ medusa.carts.create({
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts`, {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
sales_channel_id: salesChannelId
|
||||
})
|
||||
sales_channel_id: salesChannelId,
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({cart}) => {
|
||||
console.log(cart.id);
|
||||
});
|
||||
.then(({ cart }) => {
|
||||
console.log(cart.id)
|
||||
})
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -119,11 +119,11 @@ You can update the sales channel of an existing cart by passing the `sales_chann
|
||||
|
||||
```jsx
|
||||
medusa.carts.update(cartId, {
|
||||
sales_channel_id: salesChannelId
|
||||
sales_channel_id: salesChannelId,
|
||||
})
|
||||
.then(({ cart }) => {
|
||||
console.log(cart.id)
|
||||
})
|
||||
.then(({cart}) => {
|
||||
console.log(cart.id);
|
||||
});
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -131,16 +131,16 @@ medusa.carts.update(cartId, {
|
||||
|
||||
```jsx
|
||||
fetch(`<SERVER_URL>/store/carts/${cartId}`, {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
sales_channel_id: salesChannelId
|
||||
})
|
||||
sales_channel_id: salesChannelId,
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then(({cart}) => console.log(cart.id));
|
||||
.then(({ cart }) => console.log(cart.id))
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
Reference in New Issue
Block a user