summaryrefslogtreecommitdiffstats
path: root/components/TakeMyMoney.js
blob: 143f990780c0a8f33c16caf3c9e4e5caacd57aaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { Component } from 'react';
import StripeCheckout from 'react-stripe-checkout';
import { CREATE_ORDER_MUTATION } from '../queries';
import { graphql } from 'react-apollo';


class TakeMyMoney extends Component {
  onToken = async (res) => {
    const token = res.id;
    console.log(`Going to make a purchase with ${token}`);
    const charge = await this.props.createOrder({ variables: { token }});
    alert(`Back from the charge! ${charge.id}`);
    console.log(charge);

  }
  render() {
    return (
      // ...
      <StripeCheckout
        {...this.props}
        token={this.onToken}
        stripeKey="pk_lclTtThFp8CnO3QtEZSd8HA9mFUps"
        currency="USD"
      >
        {this.props.children}
      </StripeCheckout>
    )
  }
}

export default graphql(CREATE_ORDER_MUTATION, { name: 'createOrder' })(TakeMyMoney);