Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private onClick = async () => {
- const {cart} = this.props;
- // this.state.stripe
- // .createPaymentMethod("card", {billing_details: {name: "Jenny Rosen"}})
- // .then(({paymentMethod}: any) => {
- // console.log("Received Stripe PaymentMethod:", paymentMethod);
- // });
- const result = await this.props.stripe.createToken();
- console.log(result);
- const items = cart.products.map((item: any) => {
- const { variantId = item.id, quantity } = item;
- return { quantity, variantId };
- });
- const {
- email,
- firstName,
- lastName,
- country,
- city,
- postalCode,
- streetAddress1,
- phone,
- shippingMethodId,
- } = this.state;
- const variablesCheckout = {
- email,
- shippingAddress: {
- firstName,
- lastName,
- country,
- city,
- postalCode,
- streetAddress1,
- phone,
- },
- lines: items,
- };
- const response = this.checkout
- ? {data: {checkoutCreate: {checkout: this.checkout, errors: []}}}
- : await (client as ApolloClient<{}>).mutate({
- variables: variablesCheckout,
- mutation: checkoutCreateMutation,
- fetchPolicy: "no-cache",
- });
- const { errors, checkout } = response.data.checkoutCreate;
- if (errors.length > 0) {
- this.setState({ errors: errors.map((item: any) => item.field) });
- return;
- } else {
- this.checkout = checkout;
- const variablesShipping = {
- checkoutId: checkout.id,
- shippingMethodId,
- };
- const update = await (client as ApolloClient<{}>).mutate({
- variables: variablesShipping,
- mutation: checkoutShippingMethodUpdate,
- fetchPolicy: "no-cache",
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement