最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - Unable to Process UPI Payments in IOS with requestSubscription Function in React Native IAP - Stack Overflow

programmeradmin9浏览0评论

Here is my code for IOS:-

  const handleBuySubscription = async (productId: any) => {
    try {
      setLoading(true);
      await clearTransactionIOS();
      console.log('in handle buy transaction');
      if (token?.appAccountToken) {
        const purchaseRequest: SubscriptionPurchase = await requestSubscription(
          {
            sku: productId,
            appAccountToken: token?.appAccountToken,
          }
        );

        console.log('purchaseRequestIAP', purchaseRequest);

        const purchaseUpdateSubscription = purchaseUpdatedListener(
          async (purchase: SubscriptionPurchase) => {
            const { transactionReceipt: receipt, transactionId } = purchase;
            console.log('purchase receipt:', receipt);

            console.log('purchase details', purchase);
            if (transactionId === purchaseRequest.transactionId) {
              // verify transactionId before success response.
              console.log('purchase successfull');
              navigation.navigate(APP_PATH.ONPAYMENTSUCCESS, {
                plan: selectedPlan,
              });
              purchaseUpdateSubscription.remove(); // removing event listeners after work done.
            }
          },
          (err) => {
            console.log('Error in purchase', err);
            purchaseUpdateSubscription.remove(); // removing event listeners on failure.
          }
        );
      } else {
        /*
         * if appAccountToken is not available it will show a toast not available.
         * that's an impossible case because each user will have appAccountToken but did this to prevent app crash if this happens.
         */
        console.log('appAccountToken not set for this user');
        showToast('Not available!');
      }
      console.log('After handle buy transaction');
    } catch (error) {
      setLoading(false);
      setCurrentTransaction(null);

      if (error.code === 'E_NETWORK_ERROR') {
        showToast('Network unavailable'); // This will show toast if internet is not available while purchasing a plan.
      } else if (error.code === 'E_UNKNOWN') {
        navigation.navigate(APP_PATH.ONPAYMENTFAILED); // This will navigate to the payment failed screen if the failure reason is E_UNKNOWN. E_UNKNOWN comes when there is payment failure due to several external reason like payment method declined or not added etc.
      }

      if (error instanceof PurchaseError) {
        console.log({ message: `[${error.code}]: ${error.message}`, error });
      } else {
        console.log({
          message: 'handleBuySubscription',
          error: JSON.stringify(error),
        });
      }
    }
  };

Development:-

  1. Testing works in the sandbox environment.

  2. There is no feature to add or view balance in the sandbox environment, but there's a toggle button to simulate success or failure cases in iOS.

Production :-

  1. In production, you can add money to the Apple Wallet using UPI, cards, or net banking.

Problem :-

  1. Unable to test UPI payment results in the development environment.

  2. The requestSubscription function fails even after a successful UPI payment.

Any solutions would be greatly appreciated. Thank you in advance!

How can I handle the UPI payment scenario using the react-native-iap npm module?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论