SHARE
TWEET

Untitled

a guest Apr 25th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     private onClick = async () => {
  2.         const {cart} = this.props;
  3.         // this.state.stripe
  4.         //     .createPaymentMethod("card", {billing_details: {name: "Jenny Rosen"}})
  5.         //     .then(({paymentMethod}: any) => {
  6.         //         console.log("Received Stripe PaymentMethod:", paymentMethod);
  7.         //     });
  8.         const result = await this.props.stripe.createToken();
  9.         console.log(result);
  10.         const items = cart.products.map((item: any) => {
  11.             const { variantId = item.id, quantity } = item;
  12.             return { quantity, variantId };
  13.         });
  14.  
  15.         const {
  16.             email,
  17.             firstName,
  18.             lastName,
  19.             country,
  20.             city,
  21.             postalCode,
  22.             streetAddress1,
  23.             phone,
  24.             shippingMethodId,
  25.         } = this.state;
  26.  
  27.         const variablesCheckout = {
  28.             email,
  29.             shippingAddress: {
  30.                 firstName,
  31.                 lastName,
  32.                 country,
  33.                 city,
  34.                 postalCode,
  35.                 streetAddress1,
  36.                 phone,
  37.             },
  38.             lines: items,
  39.         };
  40.  
  41.         const response = this.checkout
  42.             ? {data: {checkoutCreate: {checkout: this.checkout, errors: []}}}
  43.             : await (client as ApolloClient<{}>).mutate({
  44.                 variables: variablesCheckout,
  45.                 mutation: checkoutCreateMutation,
  46.                 fetchPolicy: "no-cache",
  47.             });
  48.  
  49.         const { errors, checkout } = response.data.checkoutCreate;
  50.  
  51.         if (errors.length > 0) {
  52.             this.setState({ errors: errors.map((item: any) => item.field) });
  53.             return;
  54.         } else {
  55.             this.checkout = checkout;
  56.             const variablesShipping = {
  57.                 checkoutId: checkout.id,
  58.                 shippingMethodId,
  59.             };
  60.             const update = await (client as ApolloClient<{}>).mutate({
  61.                 variables: variablesShipping,
  62.                 mutation:  checkoutShippingMethodUpdate,
  63.                 fetchPolicy: "no-cache",
  64.             });
  65.         }
  66.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top