Coinbase Commerce Meteor
A wrapper package for enabling synchronous usage of Coinbase Commerce's REST API.
This package was written up primarily due to scoping issues with the official package
(coinbase-commerce-node) when used in combination with
Meteor.wrapAsync
Installation
meteor add jorgenvatle:coinbase-commerce-meteor
Setup
Import library:
1import CoinbaseCommerce from 'meteor/jorgenvatle:coinbase-commerce-meteor'; 2 3const Commerce = new CoinbaseCommerce('your-api-key', 'your-webhook-shared-secret');
Charges
Create charge
1const charge = Commerce.createCharge({ 2 name: 'The Sovereign Individual', 3 description: 'Mastering the Transition to the Information Age', 4 pricing_type: 'fixed_price', 5 local_price: { 6 amount: '100.00', 7 currency: 'USD' 8 }, 9});
Show a charge
1const charge = Commerce.showCharge('charge-id-goes-here');
Webhooks
It's important that you validate webhooks to ensure the authenticity of the webhook data. Without validation, an attacker may be able to spoof webhooks in turn allowing them to fulfill orders that aren't paid for yet.
Validate webhook
The webhook validator throws a Meteor.Error
for webhooks that don't pass the validation.
1Commerce.validateWebhook(req);
Validating with Picker:
1Picker.route('/listeners/coinbase', (params, req, res) => { 2 Commerce.validateWebhook(req); 3 4 // Handle the webhook 5});
If you'd rather not have exceptions thrown for invalid/unauthorized webhooks, use the boolean equivalent:
1if (Commerce.isValidWebhook(req)) { 2 // Webhook is valid! 3}
Contributing
When adding new features, please include tests for them. :smile:
Build & Test
Running the following command will start up both the TypeScript watcher as well as the test environment.
npm start
License
This repository is licensed under the ISC license.
Copyright (c) 2018, Jørgen Vatle.