38
loading...
This website collects cookies to deliver better user experience
ACCESS_TOKEN
value on the Heroku configuration page to the value from the previous step. Then click “Deploy app”. git clone [email protected]:square/in-app-payments-react-native-plugin
cd in-app-payments-react-native-plugin
react-native-in-app-payments-quickstart
folder. This is the quickstart application we’ll use for the rest of the tutorial.cd react-native-in-app-payments-quickstart
yarn
app/Constants.js
(view on GitHub).const SQUARE_APP_ID = 'REPLACE_ME';
// Make sure to remove trailing `/` since the CHARGE_SERVER_URL puts it
const CHARGE_SERVER_HOST = 'REPLACE_ME';
const CHARGE_SERVER_URL = `${CHARGE_SERVER_HOST}/chargeForCookie`;
const GOOGLE_PAY_LOCATION_ID = 'REPLACE_ME';
const APPLE_PAY_MERCHANT_ID = 'REPLACE_ME';
// constants require for card on file transactions
const CREATE_CUSTOMER_CARD_SERVER_URL = `${CHARGE_SERVER_HOST}/createCustomerCard`;
const CHARGE_CUSTOMER_CARD_SERVER_URL = `${CHARGE_SERVER_HOST}/chargeCustomerCard`;
const CUSTOMER_ID = 'REPLACE_ME';
module.exports = {
SQUARE_APP_ID,
CHARGE_SERVER_HOST,
CHARGE_SERVER_URL,
GOOGLE_PAY_LOCATION_ID,
APPLE_PAY_MERCHANT_ID,
CUSTOMER_ID,
CREATE_CUSTOMER_CARD_SERVER_URL,
CHARGE_CUSTOMER_CARD_SERVER_URL,
};
REPLACE_ME
with the Application ID value from above.CHANGE_SERVER_HOST
with the URL for your Heroku backend. Include the https://
but don’t include the trailing slash.REPLACE_ME
with the Location ID value from above for the Google Pay Location ID.curl --request POST https://connect.squareup.com/v2/customers \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <REPLACE ME>" \
--header "Accept: application/json" \
--data '{ "idempotency_key": <RANDOM_STRING>, "given_name": "Lauren Nobel" }'
{
"customer":{
"id":"RPRANDHZ9RV4B77TPNGF5D5WDR",
"created_at":"2019-06-14T15:32:50.412Z",
"updated_at":"2019-06-14T15:32:50Z",
"given_name":"Lauren Nobel",
"preferences":{
"email_unsubscribed":false
},
"creation_source":"THIRD_PARTY"
}
}
customer.id
field from the JSON is what we’ll need to eventually store a card on file for this customer from the app.app/Constants.js
, the file from above, set the value of the CUSTOMER_ID constant to the customer.id field above.const CUSTOMER_ID = “REPLACE_ME”
react-native run-ios
** BUILD SUCCEEDED **
and the process will exit cleanly.react-native run-android
BUILD SUCCESSFUL
and a clean process exit, the Super Cookie app should be running on the Android virtual device.HomeScreen.js
. This component decides what is rendered based on the state of the application.OrderModal
: Shows transaction details and buttons for payment methodsCardsOnFileModal
: Shows list of cards on file and a button to add a cardPendingModal
: Shows an activity indicator when a transaction is being processedapp/components
folder of the quickstart application repository. The main job of these components is to build markup for the interface, apply CSS, and trigger events when certain areas of the screen are touched.import {
SQIPCardEntry,
SQIPApplePay,
SQIPCore,
SQIPGooglePay,
} from 'react-native-square-in-app-payments';
startCardEntryFlow()
method of SQIPCardEntry is used to show the dialog for capturing credit card details. This dialog is created by the underlying native SDK so its fast and smooth. The method accepts 3 parameters - a configuration object, a success function, and a cancel function. The success function is passed a nonce that represents the card that the user entered, which can then be used to create a transaction or store a card on file.setIOSCardEntryTheme()
is used to customize the look and feel of the dialog, and that’s how we added the 🍪 emoji to the “Save” button at the dialog. The completeCardEntry()
method closes the dialog.