Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleCardPayPress = async () => {
try {
this.setState({ loading: true, token: null });
const token = await stripe.createTokenWithCard({
number: this.state.card.number,
expMonth: this.state.card.expMonth,
expYear: this.state.card.expYear,
cvc: this.state.card.cvc,
});
const { data } = await this.props.pay({
stripeTokenId: token.tokenId,
});
const payPayload = data.pay;
// If payment was instantly chargeable
if (!payPayload.redirectUrl && payPayload.order.orderStatus === 'PAID') {
return this.setState({
loading: false,
tokenizeCardAndSubmit = async () => {
this.setState({ isLoading: true, isError: false })
const { params } = this.state
try {
const token = await stripe.createTokenWithCard({ ...params })
this.props.onSubmit(token, this.state.params)
this.setState({ isLoading: false })
this.props.navigator.pop()
} catch (error) {
console.error("CreditCardForm.tsx", error)
this.setState({ isError: true, isLoading: false })
}
}
async registerAndPlaceBid() {
this.setState({ isLoading: true })
const { billingAddress, creditCardFormParams } = this.state
const token = await stripe.createTokenWithCard({
...creditCardFormParams,
name: billingAddress.fullName,
addressLine1: billingAddress.addressLine1,
addressLine2: null,
addressCity: billingAddress.city,
addressState: billingAddress.state,
addressZip: billingAddress.postalCode,
})
commitMutation(this.props.relay.environment, {
onCompleted: () => this.createBidderPosition(),
onError: e => console.error(e, e.message),
mutation: creditCardMutation,
variables: {
input: {
token: token.tokenId,
async createTokenFromAddress() {
const { billingAddress, creditCardFormParams } = this.state
return stripe.createTokenWithCard({
...creditCardFormParams,
name: billingAddress.fullName,
addressLine1: billingAddress.addressLine1,
addressLine2: billingAddress.addressLine2,
addressCity: billingAddress.city,
addressState: billingAddress.state,
addressZip: billingAddress.postalCode,
addressCountry: billingAddress.country.shortName,
})
}
async createTokenFromAddress() {
const { billingAddress, creditCardFormParams } = this.state
return stripe.createTokenWithCard({
...creditCardFormParams,
name: billingAddress.fullName,
addressLine1: billingAddress.addressLine1,
addressLine2: billingAddress.addressLine2,
addressCity: billingAddress.city,
addressState: billingAddress.state,
addressZip: billingAddress.postalCode,
addressCountry: billingAddress.country.shortName,
})
}
handleCustomPayPress = async (shouldPass = true) => {
try {
this.setState({ loading: true, token: null, error: null })
const params = shouldPass ? this.state.params : this.state.errorParams
const token = await stripe.createTokenWithCard(params)
this.setState({ loading: false, error: undefined, token })
} catch (error) {
this.setState({ loading: false, error })
}
}