This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import StripeCheckout from 'react-stripe-checkout' | |
class Stripe extends React.Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
buttonStyle: 'button primary', | |
status: 'Nothing happened yet' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gql from 'graphql-tag' | |
// Logic #1: Stripe returns token to app. | |
// No front-end graphql code necessary | |
// Logic #2: Create node in StripeToken model using customer token received from Stripe and assign user to node | |
export const createCard = gql` | |
mutation($stripeToken: String!, $userId: ID!) { | |
createStripeToken( | |
stripeToken: $stripeToken |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gql from 'graphql-tag' | |
export const userQuery = gql` | |
query { | |
user { | |
id | |
name | |
paid | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { graphql } from 'react-apollo' | |
import { userQuery, signinUser } from './graphql/user' | |
import { createCard, receiveStripeId, createPurchase, checkIfPaid, upgradeApp } from './graphql/purchase' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Stripe.propTypes = { | |
createCard: React.PropTypes.func.isRequired, | |
createPurchase: React.PropTypes.func.isRequired, | |
upgradeApp: React.PropTypes.func.isRequired, | |
data: React.PropTypes.object.isRequired | |
} | |
export default | |
graphql(signinUser, { name: 'signinUser' })( | |
graphql(createCard, { name: 'createCard' })( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
createdNode{ | |
id | |
stripeToken | |
stripeTokenToUser { | |
id | |
name | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type User { | |
id: ID! | |
name: String! | |
email: String! | |
password: String! | |
stripeId: String | |
paid: Boolean! | |
userToPurchase: [Purchase] | |
userToStripeToken: [StripeToken] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
createdNode{ | |
id | |
amount | |
description | |
isPaid | |
purchaseToUser { | |
id | |
stripeId | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
componentDidUpdate(newProps) { | |
if (this.props.data.user) { | |
const userId = this.props.data.user.id | |
if (!this.stripeTokenSubscription && !this.purchaseSubscription) { | |
// Logic #5: Create subscription to trigger response once user in User model has been successfully assigned a Stripe customer ID | |
this.stripeTokenSubscription = newProps.data.subscribeToMore({ | |
document: receiveStripeId, | |
variables: { userId }, | |
updateQuery: (previousState, { subscriptionData }) => { | |
console.log('Purchasing...') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
componentDidUpdate(newProps) { | |
if (this.props.data.user) { | |
const userId = this.props.data.user.id | |
if (!this.stripeTokenSubscription && !this.purchaseSubscription) { | |
// Logic #5: Create subscription to trigger response once user in User model has been successfully assigned a Stripe customer ID | |
this.stripeTokenSubscription = newProps.data.subscribeToMore({ | |
document: receiveStripeId, | |
variables: { userId }, | |
updateQuery: (previousState, { subscriptionData }) => { | |
console.log('Purchasing...') |
OlderNewer