Skip to content

Instantly share code, notes, and snippets.

@shokimble
Created February 12, 2018 06:03
Show Gist options
  • Save shokimble/b96c7da3bbe0d92694a18c909551e130 to your computer and use it in GitHub Desktop.
Save shokimble/b96c7da3bbe0d92694a18c909551e130 to your computer and use it in GitHub Desktop.
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View,
Button
} from 'react-native';
import stripe from 'tipsi-stripe'
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
stripe.init({
publishableKey: '<redacted>',
merchantId: 'MERCHANT_ID', // Optional
androidPayMode: 'test', // Optional, android only, 'production' by default
})
export default class App extends Component<{}> {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit App.js
</Text>
<Text style={styles.instructions}>
{instructions}
</Text>
<Button title="Android pay" onPress={async () => {
const options = {
total_price: '80.00',
currency_code: 'USD',
shipping_address_required: true,
shipping_countries: ["US", "CA"],
line_items: [{
currency_code: 'USD',
description: 'Whisky',
total_price: '50.00',
unit_price: '50.00',
quantity: '1',
}, {
currency_code: 'USD',
description: 'Vine',
total_price: '30.00',
unit_price: '30.00',
quantity: '1',
}],
}
const token = await stripe.paymentRequestWithAndroidPay(options)
console.log(token);
}}></Button>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment