2021-09-27 10:04:21 +00:00
|
|
|
import * as checkoutRequest from "../requests/Checkout";
|
|
|
|
import * as orderRequest from "../requests/Order";
|
2021-10-28 12:14:07 +00:00
|
|
|
import {
|
|
|
|
getPaymentMethodStripeId,
|
2022-08-04 10:59:42 +00:00
|
|
|
sendConfirmationToStripe,
|
2021-10-28 12:14:07 +00:00
|
|
|
} from "../requests/stripe";
|
2021-06-07 11:35:26 +00:00
|
|
|
import { createProductInChannel } from "./products/productsUtils";
|
2021-02-02 11:34:10 +00:00
|
|
|
|
2021-07-06 10:33:04 +00:00
|
|
|
export function createWaitingForCaptureOrder({
|
2021-03-12 12:14:18 +00:00
|
|
|
channelSlug,
|
|
|
|
email,
|
|
|
|
variantsList,
|
2021-12-15 12:17:35 +00:00
|
|
|
shippingMethodName,
|
2022-08-04 10:59:42 +00:00
|
|
|
address,
|
2021-07-06 10:33:04 +00:00
|
|
|
}) {
|
2021-03-12 12:14:18 +00:00
|
|
|
let checkout;
|
2021-04-16 11:36:24 +00:00
|
|
|
const auth = "token";
|
|
|
|
cy.loginInShop();
|
2021-04-28 13:10:47 +00:00
|
|
|
return checkoutRequest
|
2021-06-07 11:35:26 +00:00
|
|
|
.createCheckout({
|
|
|
|
channelSlug,
|
|
|
|
email,
|
|
|
|
variantsList,
|
|
|
|
address,
|
|
|
|
billingAddress: address,
|
2022-08-04 10:59:42 +00:00
|
|
|
auth,
|
2021-06-07 11:35:26 +00:00
|
|
|
})
|
2021-06-01 08:18:45 +00:00
|
|
|
.then(({ checkout: checkoutResp }) => {
|
2021-03-12 12:14:18 +00:00
|
|
|
checkout = checkoutResp;
|
2021-12-15 12:17:35 +00:00
|
|
|
const shippingMethodId = getShippingMethodIdFromCheckout(
|
|
|
|
checkout,
|
2022-08-04 10:59:42 +00:00
|
|
|
shippingMethodName,
|
2021-12-15 12:17:35 +00:00
|
|
|
);
|
2021-03-12 12:14:18 +00:00
|
|
|
checkoutRequest.addShippingMethod(checkout.id, shippingMethodId);
|
|
|
|
})
|
|
|
|
.then(() => addPayment(checkout.id))
|
|
|
|
.then(() => checkoutRequest.completeCheckout(checkout.id))
|
2021-05-16 11:38:53 +00:00
|
|
|
.then(({ order }) => ({ checkout, order }));
|
2021-03-12 12:14:18 +00:00
|
|
|
}
|
2021-05-16 11:38:53 +00:00
|
|
|
|
2021-12-15 12:17:35 +00:00
|
|
|
export function getShippingMethodIdFromCheckout(checkout, shippingMethodName) {
|
2022-01-31 08:37:49 +00:00
|
|
|
const availableShippingMethodsLength = checkout.shippingMethods.length;
|
|
|
|
if (availableShippingMethodsLength === 0) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return checkout.shippingMethods.find(
|
2022-08-04 10:59:42 +00:00
|
|
|
element => element.name === shippingMethodName,
|
2022-01-31 08:37:49 +00:00
|
|
|
).id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function updateShippingInCheckout(checkoutToken, shippingMethodName) {
|
|
|
|
return checkoutRequest.getCheckout(checkoutToken).then(checkout => {
|
|
|
|
const shippingMethodId = getShippingMethodIdFromCheckout(
|
|
|
|
checkout,
|
2022-08-04 10:59:42 +00:00
|
|
|
shippingMethodName,
|
2022-01-31 08:37:49 +00:00
|
|
|
);
|
|
|
|
return checkoutRequest.checkoutShippingMethodUpdate(
|
|
|
|
checkout.id,
|
2022-08-04 10:59:42 +00:00
|
|
|
shippingMethodId,
|
2022-01-31 08:37:49 +00:00
|
|
|
);
|
|
|
|
});
|
2021-12-15 12:17:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-23 10:15:39 +00:00
|
|
|
export function createCheckoutWithVoucher({
|
|
|
|
channelSlug,
|
|
|
|
email = "email@example.com",
|
|
|
|
variantsList,
|
2022-02-11 14:39:10 +00:00
|
|
|
productQuantity = 1,
|
2021-03-23 10:15:39 +00:00
|
|
|
address,
|
2021-12-15 12:17:35 +00:00
|
|
|
shippingMethodName,
|
2021-03-23 10:15:39 +00:00
|
|
|
voucherCode,
|
2022-08-04 10:59:42 +00:00
|
|
|
auth,
|
2021-03-23 10:15:39 +00:00
|
|
|
}) {
|
|
|
|
let checkout;
|
2021-04-28 13:10:47 +00:00
|
|
|
return checkoutRequest
|
2021-09-29 13:24:47 +00:00
|
|
|
.createCheckout({
|
|
|
|
channelSlug,
|
2022-02-11 14:39:10 +00:00
|
|
|
productQuantity,
|
2021-09-29 13:24:47 +00:00
|
|
|
email,
|
|
|
|
variantsList,
|
|
|
|
address,
|
|
|
|
billingAddress: address,
|
2022-08-04 10:59:42 +00:00
|
|
|
auth,
|
2021-09-29 13:24:47 +00:00
|
|
|
})
|
2021-06-01 08:18:45 +00:00
|
|
|
.then(({ checkout: checkoutResp }) => {
|
2021-03-23 10:15:39 +00:00
|
|
|
checkout = checkoutResp;
|
2021-12-15 12:17:35 +00:00
|
|
|
const shippingMethodId = getShippingMethodIdFromCheckout(
|
|
|
|
checkout,
|
2022-08-04 10:59:42 +00:00
|
|
|
shippingMethodName,
|
2021-12-15 12:17:35 +00:00
|
|
|
);
|
2021-03-23 10:15:39 +00:00
|
|
|
checkoutRequest.addShippingMethod(checkout.id, shippingMethodId);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
checkoutRequest.addVoucher(checkout.id, voucherCode);
|
|
|
|
})
|
2021-09-29 13:24:47 +00:00
|
|
|
.then(resp => ({
|
|
|
|
addPromoCodeResp: resp.body.data.checkoutAddPromoCode,
|
2022-08-04 10:59:42 +00:00
|
|
|
checkout,
|
2021-09-29 13:24:47 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function purchaseProductWithPromoCode({
|
|
|
|
channelSlug,
|
|
|
|
email = "email@example.com",
|
|
|
|
variantsList,
|
|
|
|
address,
|
2022-01-31 08:37:49 +00:00
|
|
|
shippingMethodName,
|
2021-09-29 13:24:47 +00:00
|
|
|
voucherCode,
|
2022-08-04 10:59:42 +00:00
|
|
|
auth,
|
2021-09-29 13:24:47 +00:00
|
|
|
}) {
|
|
|
|
let checkout;
|
|
|
|
|
|
|
|
return createCheckoutWithVoucher({
|
|
|
|
channelSlug,
|
|
|
|
email,
|
|
|
|
variantsList,
|
|
|
|
address,
|
2022-01-31 08:37:49 +00:00
|
|
|
shippingMethodName,
|
2021-09-29 13:24:47 +00:00
|
|
|
voucherCode,
|
2022-08-04 10:59:42 +00:00
|
|
|
auth,
|
2021-09-29 13:24:47 +00:00
|
|
|
})
|
|
|
|
.then(({ checkout: checkoutResp }) => {
|
|
|
|
checkout = checkoutResp;
|
|
|
|
addPayment(checkout.id);
|
|
|
|
})
|
|
|
|
.then(() => checkoutRequest.completeCheckout(checkout.id))
|
|
|
|
.then(({ order }) => ({ checkout, order }));
|
2021-03-23 10:15:39 +00:00
|
|
|
}
|
|
|
|
|
2021-05-31 07:50:31 +00:00
|
|
|
export function createReadyToFulfillOrder({
|
2021-03-12 12:14:18 +00:00
|
|
|
customerId,
|
2022-10-25 11:44:10 +00:00
|
|
|
shippingMethod,
|
2021-03-12 12:14:18 +00:00
|
|
|
channelId,
|
Feature - channels per plugin (#1093)
* Update schema
* Update queries, mutations, and types
* Add render with dividers util function
* Add plugin details channels card component
* Update plugin details to use channels
* Update stories
* Update plugin configuration type across the app, fix some other types, temporarily comment some things out in plugins list so types match"
* Update schema
* Update types
* Update plugins list to show channels and global statuses, add plugin channel status, update status label component
* Add render with dividers util function
* Comment out some stuff for types to match - temporary
* Add useChannelsSearchWithLoadMore util to imitate loading more from backend for channels list with load more
* Change filters logic to be able to display multiple fields in a field section and add it to plugins view
* Add scroll option to plugin availability popup on plugin list
* Fix plugin list page story
* Temporarily comment some stuff out, fix some types
* Add filters errors WIP
* Fix filters not updating list
* Add error handling to plugins list filters and filters in general
* Rename some components according to review
* Move useChannelsSearch and useChannelsSearchWithLoadMore to hooks, change some imports accordingly
* Fix imports
* Move render collection with dividers to a component, fix usages
* Replace channels with load more and search query to base channels query
* Change render with dividers function to take in a component instead of render function
* Update tests
* Extract messages
* Remove unnecessary imports
* Fix filters - autocomplete messing items order sometimes & some fields not working
* Update plugin update mutation variables - change channelId to channel
* fix failing tests
* Add test ids
* fix failing tests
* fix failing tests
* Rename misc.tsx to ts
* Remove usage of render collection with diviers, change it to CollectionWithDividers component
* Remove unnecessary imports
* Update messages ids
* Update snapshots
Co-authored-by: Karolina Rakoczy <rakoczy.karolina@gmail.com>
2021-05-11 13:58:09 +00:00
|
|
|
variantsList,
|
2022-08-04 10:59:42 +00:00
|
|
|
address,
|
2021-05-31 07:50:31 +00:00
|
|
|
}) {
|
2021-03-12 12:14:18 +00:00
|
|
|
let order;
|
2021-05-16 11:38:53 +00:00
|
|
|
return orderRequest
|
2022-10-25 11:44:10 +00:00
|
|
|
.createDraftOrder({ customerId, channelId, address })
|
2021-03-12 12:14:18 +00:00
|
|
|
.then(orderResp => {
|
|
|
|
order = orderResp;
|
2021-03-17 10:00:30 +00:00
|
|
|
assignVariantsToOrder(order, variantsList);
|
2021-03-12 12:14:18 +00:00
|
|
|
})
|
2022-10-25 11:44:10 +00:00
|
|
|
.then(orderResp => {
|
|
|
|
shippingMethod = getShippingMethodIdFromCheckout(
|
|
|
|
orderResp.order,
|
|
|
|
shippingMethod.name,
|
|
|
|
);
|
|
|
|
orderRequest.addShippingMethod(order.id, shippingMethod);
|
|
|
|
})
|
2022-08-04 10:59:42 +00:00
|
|
|
.then(() => orderRequest.completeOrder(order.id))
|
|
|
|
.then(() => orderRequest.markOrderAsPaid(order.id));
|
2021-03-12 12:14:18 +00:00
|
|
|
}
|
2021-03-17 10:00:30 +00:00
|
|
|
|
2021-05-31 07:50:31 +00:00
|
|
|
export function createFulfilledOrder({
|
|
|
|
customerId,
|
2022-10-25 11:44:10 +00:00
|
|
|
shippingMethod,
|
2021-05-31 07:50:31 +00:00
|
|
|
channelId,
|
|
|
|
variantsList,
|
|
|
|
address,
|
|
|
|
warehouse,
|
2022-08-04 10:59:42 +00:00
|
|
|
quantity = 1,
|
2021-05-31 07:50:31 +00:00
|
|
|
}) {
|
|
|
|
return createReadyToFulfillOrder({
|
|
|
|
customerId,
|
2022-10-25 11:44:10 +00:00
|
|
|
shippingMethod,
|
2021-05-31 07:50:31 +00:00
|
|
|
channelId,
|
|
|
|
variantsList,
|
2022-08-04 10:59:42 +00:00
|
|
|
address,
|
2021-05-31 07:50:31 +00:00
|
|
|
}).then(({ order }) => {
|
|
|
|
orderRequest.fulfillOrder({
|
|
|
|
orderId: order.id,
|
|
|
|
warehouse,
|
|
|
|
quantity,
|
2022-08-04 10:59:42 +00:00
|
|
|
linesId: order.lines,
|
2021-05-31 07:50:31 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-17 10:00:30 +00:00
|
|
|
export function createOrder({
|
|
|
|
customerId,
|
2022-10-25 11:44:10 +00:00
|
|
|
shippingMethod,
|
2021-03-17 10:00:30 +00:00
|
|
|
channelId,
|
Feature - channels per plugin (#1093)
* Update schema
* Update queries, mutations, and types
* Add render with dividers util function
* Add plugin details channels card component
* Update plugin details to use channels
* Update stories
* Update plugin configuration type across the app, fix some other types, temporarily comment some things out in plugins list so types match"
* Update schema
* Update types
* Update plugins list to show channels and global statuses, add plugin channel status, update status label component
* Add render with dividers util function
* Comment out some stuff for types to match - temporary
* Add useChannelsSearchWithLoadMore util to imitate loading more from backend for channels list with load more
* Change filters logic to be able to display multiple fields in a field section and add it to plugins view
* Add scroll option to plugin availability popup on plugin list
* Fix plugin list page story
* Temporarily comment some stuff out, fix some types
* Add filters errors WIP
* Fix filters not updating list
* Add error handling to plugins list filters and filters in general
* Rename some components according to review
* Move useChannelsSearch and useChannelsSearchWithLoadMore to hooks, change some imports accordingly
* Fix imports
* Move render collection with dividers to a component, fix usages
* Replace channels with load more and search query to base channels query
* Change render with dividers function to take in a component instead of render function
* Update tests
* Extract messages
* Remove unnecessary imports
* Fix filters - autocomplete messing items order sometimes & some fields not working
* Update plugin update mutation variables - change channelId to channel
* fix failing tests
* Add test ids
* fix failing tests
* fix failing tests
* Rename misc.tsx to ts
* Remove usage of render collection with diviers, change it to CollectionWithDividers component
* Remove unnecessary imports
* Update messages ids
* Update snapshots
Co-authored-by: Karolina Rakoczy <rakoczy.karolina@gmail.com>
2021-05-11 13:58:09 +00:00
|
|
|
variantsList,
|
2022-08-04 10:59:42 +00:00
|
|
|
address,
|
2021-03-17 10:00:30 +00:00
|
|
|
}) {
|
|
|
|
let order;
|
2021-05-16 11:38:53 +00:00
|
|
|
return orderRequest
|
2022-10-25 11:44:10 +00:00
|
|
|
.createDraftOrder({ customerId, channelId, address })
|
2021-03-17 10:00:30 +00:00
|
|
|
.then(orderResp => {
|
|
|
|
order = orderResp;
|
|
|
|
assignVariantsToOrder(order, variantsList);
|
|
|
|
})
|
2022-10-25 11:44:10 +00:00
|
|
|
.then(orderResp => {
|
|
|
|
shippingMethod = getShippingMethodIdFromCheckout(
|
|
|
|
orderResp.order,
|
|
|
|
shippingMethod.name,
|
|
|
|
);
|
|
|
|
orderRequest.addShippingMethod(order.id, shippingMethod);
|
|
|
|
})
|
2021-03-17 10:00:30 +00:00
|
|
|
.then(() => orderRequest.completeOrder(order.id))
|
2023-05-11 06:46:33 +00:00
|
|
|
.then(resp => (order = resp.order));
|
2021-03-17 10:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function assignVariantsToOrder(order, variantsList) {
|
|
|
|
variantsList.forEach(variantElement => {
|
|
|
|
orderRequest.addProductToOrder(order.id, variantElement.id);
|
|
|
|
});
|
|
|
|
}
|
Feature - channels per plugin (#1093)
* Update schema
* Update queries, mutations, and types
* Add render with dividers util function
* Add plugin details channels card component
* Update plugin details to use channels
* Update stories
* Update plugin configuration type across the app, fix some other types, temporarily comment some things out in plugins list so types match"
* Update schema
* Update types
* Update plugins list to show channels and global statuses, add plugin channel status, update status label component
* Add render with dividers util function
* Comment out some stuff for types to match - temporary
* Add useChannelsSearchWithLoadMore util to imitate loading more from backend for channels list with load more
* Change filters logic to be able to display multiple fields in a field section and add it to plugins view
* Add scroll option to plugin availability popup on plugin list
* Fix plugin list page story
* Temporarily comment some stuff out, fix some types
* Add filters errors WIP
* Fix filters not updating list
* Add error handling to plugins list filters and filters in general
* Rename some components according to review
* Move useChannelsSearch and useChannelsSearchWithLoadMore to hooks, change some imports accordingly
* Fix imports
* Move render collection with dividers to a component, fix usages
* Replace channels with load more and search query to base channels query
* Change render with dividers function to take in a component instead of render function
* Update tests
* Extract messages
* Remove unnecessary imports
* Fix filters - autocomplete messing items order sometimes & some fields not working
* Update plugin update mutation variables - change channelId to channel
* fix failing tests
* Add test ids
* fix failing tests
* fix failing tests
* Rename misc.tsx to ts
* Remove usage of render collection with diviers, change it to CollectionWithDividers component
* Remove unnecessary imports
* Update messages ids
* Update snapshots
Co-authored-by: Karolina Rakoczy <rakoczy.karolina@gmail.com>
2021-05-11 13:58:09 +00:00
|
|
|
|
2021-05-16 11:38:53 +00:00
|
|
|
export function addPayment(checkoutId) {
|
|
|
|
return checkoutRequest.addPayment({
|
|
|
|
checkoutId,
|
|
|
|
gateway: "mirumee.payments.dummy",
|
2022-08-04 10:59:42 +00:00
|
|
|
token: "not-charged",
|
2021-05-16 11:38:53 +00:00
|
|
|
});
|
2021-03-12 12:14:18 +00:00
|
|
|
}
|
2021-05-16 11:38:53 +00:00
|
|
|
|
|
|
|
export function addAdyenPayment(checkoutId, amount) {
|
|
|
|
return checkoutRequest.addPayment({
|
|
|
|
checkoutId,
|
|
|
|
gateway: "mirumee.payments.adyen",
|
2022-08-04 10:59:42 +00:00
|
|
|
amount,
|
2021-05-16 11:38:53 +00:00
|
|
|
});
|
|
|
|
}
|
2021-10-28 12:14:07 +00:00
|
|
|
export function addStripePayment(checkoutId, amount, token) {
|
|
|
|
return checkoutRequest.addPayment({
|
|
|
|
checkoutId,
|
|
|
|
gateway: "saleor.payments.stripe",
|
|
|
|
amount,
|
2022-08-04 10:59:42 +00:00
|
|
|
token,
|
2021-10-28 12:14:07 +00:00
|
|
|
});
|
|
|
|
}
|
2021-05-16 11:38:53 +00:00
|
|
|
|
2021-04-28 13:10:47 +00:00
|
|
|
export function createAndCompleteCheckoutWithoutShipping({
|
2021-03-23 10:15:39 +00:00
|
|
|
channelSlug,
|
|
|
|
email,
|
|
|
|
variantsList,
|
2021-04-28 13:10:47 +00:00
|
|
|
billingAddress,
|
2022-08-04 10:59:42 +00:00
|
|
|
auth,
|
2021-03-23 10:15:39 +00:00
|
|
|
}) {
|
2021-04-28 13:10:47 +00:00
|
|
|
let checkout;
|
2021-03-12 12:14:18 +00:00
|
|
|
return checkoutRequest
|
2021-04-28 13:10:47 +00:00
|
|
|
.createCheckout({ channelSlug, email, variantsList, billingAddress, auth })
|
2021-06-01 08:18:45 +00:00
|
|
|
.then(({ checkout: checkoutResp }) => {
|
2021-04-28 13:10:47 +00:00
|
|
|
checkout = checkoutResp;
|
|
|
|
addPayment(checkout.id);
|
2021-03-23 10:15:39 +00:00
|
|
|
})
|
2021-04-28 13:10:47 +00:00
|
|
|
.then(() => checkoutRequest.completeCheckout(checkout.id))
|
2021-05-16 11:38:53 +00:00
|
|
|
.then(({ order }) => ({ checkout, order }));
|
2021-02-02 11:34:10 +00:00
|
|
|
}
|
2021-06-07 11:35:26 +00:00
|
|
|
|
|
|
|
export function createOrderWithNewProduct({
|
|
|
|
attributeId,
|
|
|
|
categoryId,
|
|
|
|
productTypeId,
|
|
|
|
channel,
|
|
|
|
name,
|
|
|
|
warehouseId,
|
|
|
|
quantityInWarehouse = 1,
|
|
|
|
trackInventory = true,
|
2021-12-15 12:17:35 +00:00
|
|
|
shippingMethod,
|
2022-08-04 10:59:42 +00:00
|
|
|
address,
|
2021-06-07 11:35:26 +00:00
|
|
|
}) {
|
2021-07-12 08:50:50 +00:00
|
|
|
let variantsList;
|
2021-06-07 11:35:26 +00:00
|
|
|
return createProductInChannel({
|
|
|
|
attributeId,
|
|
|
|
categoryId,
|
|
|
|
productTypeId,
|
|
|
|
channelId: channel.id,
|
|
|
|
name,
|
|
|
|
warehouseId,
|
|
|
|
quantityInWarehouse,
|
2022-08-04 10:59:42 +00:00
|
|
|
trackInventory,
|
2021-07-12 08:50:50 +00:00
|
|
|
})
|
|
|
|
.then(({ variantsList: variantsListResp }) => {
|
|
|
|
variantsList = variantsListResp;
|
|
|
|
createWaitingForCaptureOrder({
|
|
|
|
channelSlug: channel.slug,
|
|
|
|
email: "email@example.com",
|
|
|
|
variantsList,
|
2021-12-15 12:17:35 +00:00
|
|
|
shippingMethodName: shippingMethod.name,
|
2022-08-04 10:59:42 +00:00
|
|
|
address,
|
2021-07-12 08:50:50 +00:00
|
|
|
});
|
2021-07-06 10:33:04 +00:00
|
|
|
})
|
2021-07-12 08:50:50 +00:00
|
|
|
.then(({ order, checkout }) => ({ order, checkout, variantsList }));
|
2021-06-07 11:35:26 +00:00
|
|
|
}
|
2021-10-28 12:14:07 +00:00
|
|
|
|
|
|
|
export function addStripePaymentAndGetConfirmationData({
|
|
|
|
card,
|
|
|
|
checkoutId,
|
2022-08-04 10:59:42 +00:00
|
|
|
amount,
|
2021-10-28 12:14:07 +00:00
|
|
|
}) {
|
|
|
|
let paymentMethodId;
|
|
|
|
|
|
|
|
return getPaymentMethodStripeId(card)
|
|
|
|
.then(resp => {
|
|
|
|
paymentMethodId = resp.body.id;
|
|
|
|
addStripePayment(checkoutId, amount, resp.body.id);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
checkoutRequest.completeCheckout(checkoutId);
|
|
|
|
})
|
|
|
|
.then(resp => {
|
|
|
|
const confirmationData = JSON.parse(resp.confirmationData);
|
|
|
|
sendConfirmationToStripe(paymentMethodId, confirmationData.id, false);
|
|
|
|
})
|
|
|
|
.then(resp => resp);
|
|
|
|
}
|