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!).
A product is a type of purchase a user can make. It has a `name`, `amount` (in cents), `currency`, and `description`.
New products are defined using the `addProduct` function, which takes two arguments. The first argument is a unique **product key** used to identify the product. The second argument can be an object (for "static" products like a subscription):
Or it can be a function (for "dynamic" products like in an e-commerce site) that takes the associated document (i.e. the product being sold) as argument and returns an object:
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.
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 `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`.
The `createChargeMutation` GraphQL mutation will then return that job according to the `fragment` property specified.
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.
The best way to update a document based on a successful charge is by using the `collection.charge.sync` callback.
Callback functions on this hook will run with a MongoDB `modifier` as the first argument (although note that only `$set` and `$unset` operations are supported here), the `document` associated with the charge as their second argument, and the `charge` object as their third argument.
Because the callback is added in a **sync** manner, the final document returned by the `createChargeMutation` mutation will include any new values set by the callback hook.
#### Example 1: Setting a job offer as paid
```js
import { addCallback } from 'meteor/vulcan:core';
function setToPaidOnCharge (modifier, job, charge) {
#### Example 3: Giving a user access to a specific document
We'll pass the `videoId` property to our `Checkout` component (`property={{videoId: video._id}}`) to make it accessible as `charge.properties.videoId` inside the callback:
```js
import { addCallback } from 'meteor/vulcan:core';
function giveAccessToVideo (modifier, user, charge) {