more payments docs updates

This commit is contained in:
SachaG 2017-05-31 10:32:35 +09:00
parent 0e7b3502f3
commit 11c46416d8

View file

@ -2,30 +2,18 @@
This package helps you process charges with Vulcan. It currently only supports Stripe, but other payment processors may be supported in the future (PRs welcome!). This package helps you process charges with Vulcan. It currently only supports Stripe, but other payment processors may be supported in the future (PRs welcome!).
### Overview ## Overview
This package does the following things: This package does the following things:
- Provide a button that triggers the [Stripe Checkout](https://stripe.com/checkout) form. - Provide a button that triggers the [Stripe Checkout](https://stripe.com/checkout) form.
- Once the form is submitted, trigger a GraphQL mutation that will perform the charge. - Once the form is submitted, trigger a GraphQL mutation that will:
- The mutation then returns a document associated with the charge. - Perform the charge.
- Create a new Charge.
- Modify a document associated with the charge.
- The mutation then returns a document associated with the charge to the client.
### Charges ## Settings
Charges are stored in the database with the following fields:
- `_id`: the charge's id.
- `createdAt`: the charge's timestamp.
- `userId`: the Vulcan `_id` of the user performing the purchase.
- `tokenId`: the charge token's id.
- `productKey`: the key corresponding to the product being purchased, as defined with `addProduct`.
- `type`: the type of charge (currently only `stripe` is supported).
- `test`: whether the operation is a test or not.
- `data`: a JSON object containing all charge data generated by the payment processor.
- `properties`: a JSON object containing any custom properties passed by the client.
- `ip`: the IP address of the client performing the purchase.
### Settings
Stripe requires the following public setting in your `settings.json`. Stripe requires the following public setting in your `settings.json`.
@ -49,7 +37,22 @@ As well as the following private setting (can be stored in the setting's root or
} }
``` ```
### Products ## Charges
Charges are stored in the database with the following fields:
- `_id`: the charge's id.
- `createdAt`: the charge's timestamp.
- `userId`: the Vulcan `_id` of the user performing the purchase.
- `tokenId`: the charge token's id.
- `productKey`: the key corresponding to the product being purchased, as defined with `addProduct`.
- `type`: the type of charge (currently only `stripe` is supported).
- `test`: whether the operation is a test or not.
- `data`: a JSON object containing all charge data generated by the payment processor.
- `properties`: a JSON object containing any custom properties passed by the client.
- `ip`: the IP address of the client performing the purchase.
## Products
A product is a type of purchase a user can make. It has a `name`, `amount` (in cents), `currency`, and `description`. A product is a type of purchase a user can make. It has a `name`, `amount` (in cents), `currency`, and `description`.
@ -80,7 +83,7 @@ addProduct('book', book => ({
Make sure you define your products in a location accessible to both client and server, in order to access them both on the front-end to configure Stripe Checkout, and in the back-end to perform the actual charge. Make sure you define your products in a location accessible to both client and server, in order to access them both on the front-end to configure Stripe Checkout, and in the back-end to perform the actual charge.
### Checkout Component ## Checkout Component
```js ```js
<Components.Checkout <Components.Checkout
@ -101,21 +104,42 @@ Make sure you define your products in a location accessible to both client and s
- `fragmentName`: a registeredGraphQL fragment name. - `fragmentName`: a registeredGraphQL fragment name.
- `properties`: any other properties you want to pass on to `createChargeMutation` on the server. - `properties`: any other properties you want to pass on to `createChargeMutation` on the server.
### Associating a Collection Document ## Associating a Collection Document
The Vulcan Charge package requires associating a document with a purchase, typically the item being paid for. For example, maybe you want people to buy access to a file hosted on your servers, and give them download access once the transaction is complete. The Vulcan Charge package requires associating a document with a purchase, typically the item being paid for. For example, maybe you want people to buy access to a file hosted on your servers, and give them download access once the transaction is complete.
The `associatedCollection` and `associatedId` props give you an easy way to implement this by automatically setting a `chargeId` field on the document once the charge succeeds. The `associatedCollection` and `associatedId` props give you an easy way to implement this by automatically setting a `chargeIds` field on the document once the charge succeeds.
For example, if you pass `associatedCollection={Jobs}` and `associatedId="foo123"` to the Checkout component, the resulting charge's `_id` will automatically be added to a `chargeIds` array on job `foo123`. For example, if you pass `associatedCollection={Jobs}` and `associatedId="foo123"` to the Checkout component, the resulting charge's `_id` will automatically be added to a `chargeIds` array on job `foo123`.
The `createChargeMutation` GraphQL mutation will then return that job according to the `fragment` property specified. The `createChargeMutation` GraphQL mutation will then return that job according to the `fragment` property specified.
### The Chargeable Type Note: you will need to make sure that your collection accepts this `chargeIds` field. For example:
In order to be able to return any associated document, the package creates a new `Chargeable` type that is an union of every chargeable collection's types. ```js
Jobs.addField([
{
fieldName: 'chargeIds',
fieldSchema: {
type: Array,
optional: true,
}
},
{
fieldName: 'chargeIds.$',
fieldSchema: {
type: String,
optional: true,
}
}
]);
```
### Post-Charge Updates #### The "Chargeable" Type
In order to be able to return any associated document, the package creates a new `Chargeable` GraphQL type that is an union of every collection's types.
## Post-Charge Updates
The best way to update a document based on a successful charge is by using the `collection.charge.sync` callback. The best way to update a document based on a successful charge is by using the `collection.charge.sync` callback.