TIL: RN | 인앱 결제 react-native-iap (8) iOS Methods - 221130

Lumpen·2022년 11월 30일
0

RN인앱결제

목록 보기
8/16
post-custom-banner

buyPromotedProductIOS

Buy the currently selected promoted product.
프로모션된 제품에 대한 결제 프로세스를 시작합니다.

Should only be called in response to the iap-promoted-product event.

Signature

buyPromotedProductIOS(): Promise<void>

Usage

import React from 'react';
import {Button} from 'react-native';
import {buyPromotedProductIOS} from 'react-native-iap';

const App = () => {
  const handleBuy = async () => await buyPromotedProductIOS();

  return (
    <Button title="Buy" onPress={handleBuy} />
  );
}

clearProductsIOS

Clear valid products.
Apple 서버에서 확인한 모든 제품을 제거합니다.

Signature

clearProductsIOS(): Promise<void>

Usage

import React, {useEffect} from 'react';
import {View} from 'react-native';
import {clearProductsIOS} from 'react-native-iap';

const App = () => {
  useEffect(() => {
    void clearProductsIOS();
  }, []);

  return <View />;
}

clearTransactionIOS

Clear the remaining transactions.

See https://github.com/dooboolab/react-native-iap/issues/257
See https://github.com/dooboolab/react-native-iap/issues/801

Signature

clearTransactionIOS(): Promise<void>

Usage

import React, {useEffect} from 'react';
import {View} from 'react-native';
import {clearTransactionIOS} from 'react-native-iap';

const App = () => {
  useEffect(() => {
    void clearTransactionIOS();
  }, [])

  return <View />;
}

getPendingPurchasesIOS

완료 대기 중인 모든 트랜잭션을 가져옵니다.

Signature

getPendingPurchasesIOS(): Promise<Purchase[]>;

Usage

import React from 'react';
import {Button} from 'react-native';
import {getPendingPurchasesIOS} from 'react-native-iap';

const App = () => {
  const handlePendingPurchases = async () => await getPendingPurchasesIOS();

  return (
    <Button title="Pending purchases" onPress={handlePendingPurchases} />
  )
}

getPromotedProductIOS

앱스토어에서 제품을 홍보해야 한다.
앱스토어 대신 앱에서 앱스토어 구매를 계속해야 함을 나타냅니다.

Signature

getPromotedProductIOS(): Promise<ProductProduct | null>;

Usage

import React, {useCallback} from 'react';
import {View} from 'react-native';
import {getPromotedProductIOS} from 'react-native-iap';

const App = () => {
  const promotedProduct = useCallback(async () => await getPromotedProductIOS());

  return <View />;
}

TODO: works with listener to get the products

getReceiptIOS

현재 영수증을 가져옵니다.

Signature

getReceiptIOS(): Promise<string>;

Usage

import {useCallback} from 'react';
import {getReceiptIOS} from 'react-native-iap';

const receipt = useCallback(async () => await getReceiptIOS());

presentCodeRedemptionSheetIOS

App Store Connect에서 생성한 구독 오퍼 코드를 사용자가 상환할 수 있는 시트를 표시합니다.

Signature

presentCodeRedemptionSheetIOS(): Promise<null>;

Usage

import React from 'react';
import {Button} from 'react-native';
import {presentCodeRedemptionSheetIOS} from 'react-native-iap';

const App = () => {
  const handleRedemption = async () => {
    await presentCodeRedemptionSheetIOS();
  }

  return (
    <Button title="Redeem" onPress={handleRedemption} />
  )
}

requestPurchaseWithOfferIOS

오퍼가 있는 제품 또는 구독을 구입합니다.
서버에서 가져와야 하는 일부 정보를 사용하여 결제 프로세스를 실행합니다.

Signature

requestPurchaseWithOfferIOS(
  /** The product identifier */
  sku: Sku,

  /** An user identifier on you system */
  forUser: string,

  /** The offer information */
  withOffer: PaymentDiscount,
): Promise<void>

Usage

import React from 'react';
import {Button} from 'react-native';
import {requestPurchaseWithOfferIOS} from 'react-native-iap';

const App = () => {
  const handlePurchase = async () => {
    await requestPurchaseWithOfferIOS({sku: 'productId', forUser: 'user-id', withOffer: {
      identifier: 'string',
      keyIdentifier: 'string',
      nonce: 'string',
      signature: 'string',
      timestamp: Date.now(),
    }});
  }

  return (
    <Button title="Buy" onPress={handlePurchase} />
  );
}

requestPurchaseWithQuantityIOS

제품에 대한 수량이 포함된 구매를 요청합니다.
응답은 PurchaseUpdateListener를 통해 수신됩니다.

Signature

requestPurchaseWithQuantityIOS(
  /** The product's sku/ID */
  sku: Sku,

  /** The quantity to request to buy */
  quantity: number,
): Promise<ProductPurchase>

Usage

import React from 'react';
import {Button} from 'react-native';
import {requestPurchaseWithQuantityIOS} from 'react-native-iap';

const App = () => {
  const handlePurchase = async () => {
    await requestPurchaseWithQuantityIOS('productId', 2);
  }

  return (
    <Button title="Purchase" onPress={handlePurchase} />
  );
}

validateReceiptIOS

영수증을 확인합니다.

Signature

validateReceiptIOS(
  /** The receipt body to send to apple server. */
  receiptBody: Record<string, unknown>,

  /** Whether this is in test environment which is sandbox. */
  isTest?: boolean,
): Promise<ResponseBody>

Usage

import React from 'react';
import {Button} from 'react-native';
import {validateReceiptIOS} from 'react-native-iap';

const App = () => {
  const handleValidate = async () => {
    await validateReceiptIOS({
      'receipt-data': '...',
    });
  }

  return (
    <Button title="Validate" onPress={handleValidate} />
  );
}
profile
떠돌이 생활을 하는. 실업자, 부랑 생활을 하는
post-custom-banner

0개의 댓글