npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-in-app-purchase-helper

v1.0.7

Published

In-App Purchase helper for react native cli

Downloads

431

Readme

React Native In-App Purchase Helper is a React Native library designed to simplify in-app purchase flows for both iOS and Android. In-app purchases can sometimes be complex to implement, so this library aims to offer a streamlined and more flexible approach. It provides utility functions to manage in-app purchases, handle receipt verification seamlessly, and allows developers to integrate payment flows with shorter, more efficient code. With this package, you can reduce the complexity of IAP operations while maintaining full control over the process.

Contents

📋 Requirements

React Native In-App Purchase Helper can target iOS 13.4 and Android 6.0 (API 23) or newer. You can use Windows, macOS, or Linux as your development operating system, but building and running iOS apps is limited to macOS.

Requirements Packages:

"react-native-iap" This library is used to sell digital content and subscriptions in your app via the App Store and Google Play Store. It allows managing IAP processes such as purchases, product lists and receipt verification.

🎉 Features

Easy Integration: Quickly set up in-app purchases in your React Native app. Cross-Platform: Supports both iOS and Android. Receipt Verification: Easily verify purchase receipts for security.

🚀 Getting Started

npm kullanarak yükleyin

  npm install react-native-in-app-purchase-helper

Import the helper functions into your project:

import {verifyTransaction,fetchPrices,createPaymentAndroid,createPaymentIOS} 
 from 'react-native-in-app-purchase-helper';

Fetching Product Prices and Defining Packages

const packageDetails = [
  {
    id: 'basic',
    androidSKUs: ['basic_android'],
    iosSKUs: ['basic_ios'],
  },
  {
    id: 'premium',
    androidSKUs: ['premium_android'],
    iosSKUs: ['premium_ios'],
  },
  {
    id: 'pro',
    androidSKUs: ['pro_android'],
    iosSKUs: ['pro_ios'],
  },
];

async function displayPackagePrices() {
  try {
    const prices = await fetchPrices(packageDetails);
    prices.forEach(pkg => {
      console.log(`Package: ${pkg.id}, Price: ${pkg.price}`);
    });
  } catch (error) {
    console.error('Error displaying prices:', error);
  }
}

Creating a Payment Method for Android

async function purchasePackage(packageId) {
  const selectedPackage = packageDetails.find(pkg => pkg.id === packageId);
  if (!selectedPackage) {
    console.error('Invalid package selected');
    return;
  }

  try {
    if (Platform.OS === 'android') {
      const purchase = await createPaymentAndroid(selectedPackage);
      console.log('Purchase successful:', purchase);
    } else if (Platform.OS === 'ios') {
      const ITUNES_SHARED_SECRET = 'your_itunes_shared_secret';
      const purchase = await createPaymentIos(selectedPackage, ITUNES_SHARED_SECRET);
      console.log('Purchase successful:', purchase);
    }
  } catch (error) {
    console.error('Error during purchase:', error);
  }
}

// For example, the user wants to purchase the premium package:
purchasePackage('premium');

Continuing a Payment

async function purchasePackage(packageId) {
  const selectedPackage = packageDetails.find(pkg => pkg.id === packageId);
  if (!selectedPackage) {
    console.error('Invalid package selected');
    return;
  }
  try {
    if (Platform.OS === 'android') {
      const purchase = await createPaymentAndroid(selectedPackage);
      console.log('Purchase successful:', purchase);
    } else if (Platform.OS === 'ios') {
      const ITUNES_SHARED_SECRET = 'your_itunes_shared_secret';
      const purchase = await createPaymentIos(selectedPackage, ITUNES_SHARED_SECRET);
      console.log('Purchase successful:', purchase);
    }
  } catch (error) {
    console.error('Error during purchase:', error);
  }
}
// For example, user wants to buy premium package:
purchasePackage('premium');

Verifying a Transaction (Only for IOS)

const isValid = await verifyTransaction(transactionReceipt, ITUNES_SHARED_SECRET);
if (isValid.valid) { 
  console.log('Purchase is valid.');
} else {
  console.error('Purchase is invalid.');
}

Usage Scenario:

Get Product Prices on App Startup and use to show it to the user

Show the prices of the products to the user by calling the getProductPrices(named for example) function at the beginning of your application. When User Wants to Buy a Product:

Have the user purchase the product of their choice by calling the launchPurchase(named for example) function. Perform Post-Purchase Actions:

Complete and verify the payment using the ProcessPayment(named for example) function.

👏 How to Contribute

The main purpose of this repository is to continue evolving React Native core. We want to make contributing to this project as easy and transparent as possible, and we are grateful to the community for contributing bug fixes and improvements.

Maintained By

Maintainer

This project is maintained and supported by idonidella.

📄 License

MIT