0.1.2 • Published 7 years ago
react-payment-request v0.1.2
React Payment Request
A Payment Request component for React.js
Installation
Npm
npm install react-payment-request --save
Umd
<script src="https://unpkg.com/react-payment-request/dist/react-payment-request.js"></script>
Usage
const details = {...}
const methodData = [...]
const options = {...}
const getOptionsforAddress = shippingAddress => {...}
const updateTotal = shippingOption => {...}
<ReactPaymentRequest
details={details}
methodData={methodData}
onError={error => console.log('💩', error)}
onShippingAddressChange={(request, resolve, reject) => {
details.shippingOptions = getOptionsforAddress(request.shippingAddress)
resolve(details)
}}
onShippingOptionChange={(request, resolve, reject) => {
details.shippingOptions = updateTotal(request.shippingOption)
resolve(details)
}}
onSuccess={result => result.complete('success')}
options={options}
>
<button>Pay</button>
</ReactPaymentRequest>
API
Parameter | Type | Description |
---|---|---|
details | object | Required information about transaction. |
methodData | array | Required payment method data. |
onError | func | Something bad happened. |
onShippingAddressChange | func | When user selects a shipping address. |
onShippingOptionChange | func | When user selects a shipping option. |
onSuccess | func | Process paymentResponse here. |
options | object | Optional parameter for things like shipping, etc. |
Test
npm test