0.0.1-alpha001 • Published 6 months ago

@tosspayments/payment-sdk-react-native v0.0.1-alpha001

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

payment-sdk-react-native

Payment SDK for React Native

Installation

# npm
npm install @tosspayments/payment-sdk-react-native

# yarn
yarn add @tosspayments/payment-sdk-react-native

Usage

import { PaymentContextProvider, usePaymentWidget } from "payment-sdk-react-native";

// ...
export default function App() {
  const [amount, onChangeAmount] = useState<Amount>({
    value: 1000,
    currency: 'KRW',
    country: 'KR',
  });
  return <PaymentContextProvider 
    clientKey={`test_ck_0Poxy1XQL8R4P1zpv14V7nO5Wmlg`}
    customerKey={`TOSSPAYMENTS`}
    onSuccess={(success) => {
      Alert.alert('결제성공', `${JSON.stringify(success)}`);
    }}
    onFail={(fail) => {
      Alert.alert(`결제실패`, `${JSON.stringify(fail)}`);
    }}
  >
    <Widget amount={amount}>
  </PaymentContextProvider>
}

function Widget({ amount }: { amount: Amount }) {
  const widget = usePaymentWidget();
  return (
    <>
      <PaymentMethodWidget 
        amount={amount}
        variantKey={`DEFAULT`}
      />
      <AgreementWidget>
      <Button
        title="결제요청"
        onPress={() => {
          const agreeement = widget?.getAgreementStatus();
          if (agreeement?.agreedRequiredTerms != true) {
            Alert.alert('약관에 동의하지 않았습니다.');
            return;
          }
          widget?.requestPayments?.({
            orderId: "OrderId_123",
            orderName: "김토스",
            cultureExpense: true,
          });
        }}
      />
      <Button
        title="선택된 결제수단"
        onPress={() => {
            Alert.alert(`선택된 결제수단: ${JSON.stringify(widget?.getSelectedPaymentMethod())}`);
        }}
      />
    </>
  )
}

License

MIT

1.1.0-alpha.11

6 months ago

1.1.0-alpha.10

6 months ago

1.1.0-alpha.9

6 months ago

1.1.0-alpha.8

6 months ago

1.1.0-alpha.7

6 months ago

1.1.0-alpha.6

6 months ago

1.1.0-alpha.5

6 months ago

1.1.0-alpha.4

6 months ago

1.1.0-alpha.3

6 months ago

1.1.0-alpha.2

6 months ago

1.1.0-alpha.1

6 months ago

1.0.0

6 months ago

0.0.1-alpha002

7 months ago

0.0.1-alpha001

7 months ago