未处理的拒绝(TypeError):无法读取未定义的属性“类型”

时间:2020-04-20 14:19:14

标签: javascript reactjs react-redux

我正在尝试在我的应用程序中构建一个支付网关。为此,有两种付款方式COD和ONLINE_PAYMENT,但问题是我选择COD方法时。我说错了。在线支付工作正常,它也可以重定向到/paymentsuccessfull-page,但在COD中,它可以转到paymentfailed页面。

未处理的拒绝(TypeError):无法读取未定义的属性'type'

我在这里找不到问题所在。这是我的代码。

export const intiatePaymentForBulkProducts = (aid, paymentType) => (
  dispatch
) => {
    console.log('step-0', paymentType);
  new _rest().get(URLConstants.urls.GET_ALL_ITEMS_IN_CART)
      .then((response) => {
          console.log('step-1', response);
        dispatch({
          type: types.INITIATE_PAYMENT_REQUEST,
        });
        dispatch({
          type: "SET_SNAKCBAR",
          snackbarContent: "Payment Initiating...",
        });
        const req = {};
        const cart = response.data._embedded.cartResourceList;
        let model = [];
        console.log('step-cart',cart);
        if (cart) {
          model = cart.map(item => {
            return {
              cartId: item.cartId,
              productId: item.productId,
              optionVariationId: 0,
              quantity: item.totalQuantity,
              couponId:1
            };
          });
        }

    req["couponId"] = '1';
    req["addressId"] = aid;
    req["paymentType"] = paymentType;
    req["models"] = model;

    console.log('step-2', req);
    new _rest()
      .post('order/bulk', req)
      .then((response) => {
          console.log('step-3', response);
        if(paymentType === 'COD') {
            dispatch({
                type: types.INITIATE_PAYMENT_SUCCESS,
                payload: response.data,
            });
          dispatch(history.push(`/paymentcomplete`));

        }else {
          dispatch({
            type: types.INITIATE_PAYMENT_SUCCESS,
            payload: response.data,
          });
          window.Instamojo.open(response.data.instamojoPaymentURL);
        }

      })
      .catch(error => {
        console.log("step-error", error);
        dispatch({
          type: types.INITIATE_PAYMENT_ERROR,
          error: error,
        });
          dispatch(history.push("/payment-failed"))
          // .catch((err) => console.log(err));
        dispatch({
          type: "SET_SNAKCBAR",
          snackbarContent: "Something went wrong, Please try again later...",
        });
      });
  });
};

0 个答案:

没有答案