Amazon pay React
Un-official implementation of Amazon pay in React.
Table of Contents
Usage
Install
- yarnyarn add amazon-pay-react
- npmnpm install amazon-pay-react
Getting started
Single page
For using all widgets on a single page importing AmazonPay
should be enough:
import AmazonPay from 'amazon-pay-react'; <AmazonPay ='your-cliendId' ='your-sellerId' = ='profile payments:widget' ='PwA' ='Gold' ='medium' = = = =/>
Additional options to AmazonPay component:
Attribute | Description | Type |
---|---|---|
isSandbox | Sandbox or production env | boolean |
region | Defines region, default 'us' (you can use REGION constant) | string |
onAmazonLoginReady | Function callback | function |
onAddressSelect | Function callback | function |
onPaymentSelect | Function callback | function |
onOrderReferenceCreate | Function callback | function |
handleAddressBookError | Function callback | function |
handleWalletOnPaymentSelect | Function callback, argument orderReference | function |
handleWalletError | Function callback | function |
handleConsentError | Function callback | function |
handleButtonError: | Function callback | function |
Multi page
When you want to have component per view, you must wrap each widget/component individually with the following wrapper in order to not try and render without having the script previously loaded.
import AmazonPayButton amazonBootstrapComponent from 'amazon-pay-react'; const BootstrappedAmazonPayButton = ;
Note that BootstrappedAmazonPayButton
version will require additional attributes:
Attribute | Description | Type |
---|---|---|
isSandbox | Sandbox or production env | boolean |
region | Defines region, default 'us' (you can use REGION constant) | string |
amazonScriptLoaded | True if amazon library has loaded via onAmazonLoginReady | boolean |
onAmazonLoginReady | Function callback | function |
Check this example implementation for a quick start.
Components
-
AmazonPayButton
AmazonPayButtonpropTypes =sellerId: PropTypesstringisRequiredscope: PropTypesstringisRequiredtype: PropTypesstringisRequiredcolor: PropTypesstringisRequiredsize: PropTypesstringisRequireduseAmazonAddressBook: PropTypesboolisRequiredonAuthorization: PropTypesfuncisRequired // When user authorizes, callback with response objectonError: PropTypesfunc // callback err object;onAuthorization response object:
-
AmazonAddressBook
AmazonAddressBookpropTypes =sellerId: PropTypesstringisRequiredagreementType: PropTypesstringisRequiredstyle: PropTypesobjectonReady: PropTypesfunc // Callback that provides orderReferenceonError: PropTypesfunc // Callback that provides err objectonAddressSelect: PropTypesfunc // Callback that provides orderReferenceonOrderReferenceCreate: PropTypesfunc // Callback that provides orderReference;Error object usage:
console.log(err.getErrorCode() + ': ' + err.getErrorMessage());
Order reference usage:orderReference.getAmazonOrderReferenceId();
-
Consent Widget
ConsentWidgetpropTypes =amazonBillingAgreementId: PropTypesstringisRequiredsellerId: PropTypesstringisRequiredstyle: PropTypesobjectonReady: PropTypesfunc // First load callback that provides hasConsent (true|false)onConsent: PropTypesfunc // On consent change, callback that provides hasConsent statusonError: PropTypesfunc // Callback that provides error object;
Documentation
Contributing
If you want to contribute to the library feel free to create an issue and/or a PR with a prefix of feature/your-feature-name or bugfix/your-bug-name
Development
- Running the example locally with watchyarn dev
- Testingyarn test
Note that you can swap between single page and React router version at examples/src/index.js
If you want to quick test library implementation locally you can use yarn link
.
Just don't forget to build it before that with yarn build
.
Versioning
TODO
- Update documentation
- Add more tests (need personal AWS central access)
- Add more flexibility
- Specify goals