stripe-fire
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -1,9 +0,51 @@ | ||
var charges = require('./charges.js'), | ||
customers = require('./customers.js'); | ||
var Firebase = require('firebase'), | ||
StripeObject = require('./stripe-object.js'); | ||
module.exports = function (key) { | ||
var stripe = require('stripe')(key); | ||
return { | ||
charges: charges(key), | ||
customers: customers(key) | ||
charges: function(ref, callback, accessToken, alterRequest) { | ||
var Charge = new StripeObject(stripe, 'Charge'); | ||
var chargesRef = ref instanceof Firebase ? ref : new Firebase(ref); | ||
chargesRef.on('child_added', Charge.create(callback, accessToken, alterRequest)); | ||
return { | ||
refunds: function(ref, callback, accessToken, alterRequest) { | ||
var refundsRef = ref instanceof Firebase ? ref : new Firebase(ref); | ||
refundsRef.on('child_added', Charge.createChild(chargesRef, 'Refund', callback, accessToken, alterRequest)); | ||
} | ||
}; | ||
}, | ||
coupons: function(ref, callback, accessToken, alterRequest) { | ||
var Coupon = new StripeObject(stripe, 'Coupon'); | ||
var couponsRef = ref instanceof Firebase ? ref : new Firebase(ref); | ||
couponsRef.on('child_added', Coupon.create(callback, accessToken, alterRequest)); | ||
}, | ||
customers: function(ref, callback, accessToken, alterRequest) { | ||
var Customer = new StripeObject(stripe, 'Customer'); | ||
var customersRef = ref instanceof Firebase ? ref : new Firebase(ref); | ||
customersRef.on('child_added', Customer.create(callback, accessToken, alterRequest)); | ||
return { | ||
cards: function(ref, callback, accessToken, alterRequest) { | ||
var cardsRef = ref instanceof Firebase ? ref : new Firebase(ref); | ||
cardsRef.on('child_added', Customer.createChild(customersRef, 'Card', callback, accessToken, alterRequest)); | ||
}, | ||
subscriptions: function(ref, callback, accessToken, alterRequest) { | ||
var subscriptionsRef = ref instanceof Firebase ? ref : new Firebase(ref); | ||
subscriptionsRef.on('child_added', Customer.createChild(customersRef, 'Subscription', callback, accessToken, alterRequest)); | ||
} | ||
}; | ||
}, | ||
plans: function(ref, callback, accessToken, alterRequest) { | ||
var Plan = new StripeObject(stripe, 'Plan'); | ||
var plansRef = ref instanceof Firebase ? ref : new Firebase(ref); | ||
plansRef.on('child_added', Plan.create(callback, accessToken, alterRequest)); | ||
} | ||
}; | ||
}; |
{ | ||
"name": "stripe-fire", | ||
"version": "0.1.0", | ||
"description": "uses firebase to trigger stripe api calls", | ||
"version": "0.2.0", | ||
"description": "A Node.js module that handles Stripe API calls when data is added to a Firebase reference.", | ||
"main": "lib/stripe-fire.js", | ||
@@ -26,4 +26,3 @@ "scripts": { | ||
"firebase": "^1.0.24", | ||
"stripe": "^2.8.0", | ||
"fire-child": "~0.1.1" | ||
"stripe": "^2.8.0" | ||
}, | ||
@@ -30,0 +29,0 @@ "directories": { |
108
README.md
@@ -6,3 +6,3 @@ # StripeFire | ||
A Node.js module that handles Stripe API calls when data is added to or removed from a Firebase reference. | ||
A Node.js module that handles Stripe API calls when data is added to a Firebase reference. | ||
@@ -27,5 +27,5 @@ StripeFire uses the following APIs: | ||
* `ref` *(required)*: An instance of a Firebase object or a string that points to a Firbase reference | ||
* `callback` *(optional)*: A function which is called after a child is added to the specified reference **and** the API request is sent to Stripe; the function accepts two parameters: an error object and the Stripe object if the request is successful | ||
* `accessToken` *(optional)*: A string or function which generates an access token to be sent with the Stripe API request (used for Stripe Connect); the function accepts one parameter: the data set in the Firebase child | ||
* `alterRequest` *(optional)*: A function which is called **before** a request is sent to Stripe; the function accepts two parameters: the data set in the Firebase child and the create function (the create function must be called to send the request to Stripe) | ||
* `callback` *(optional)*: A function which is called **after** a child is added to the specified reference *and* the API request is sent to Stripe; the function accepts two parameters: an error object and the Stripe object if the request is successful | ||
* `accessToken` *(optional)*: A string or function which returns an access token to be sent with the Stripe API request (used for Stripe Connect); the function accepts one parameter: the data set in the Firebase child | ||
* `alterRequest` *(optional)*: A function which is called **before** a request is sent to Stripe; the function accepts one parameter: the data set in the Firebase child | ||
@@ -35,3 +35,4 @@ The reference should contain children which are all similar Stripe objects. Note the children names can be anything so long as they exist in parent objects. | ||
After the API request is sent to Stripe the full Stipe object is stored at the same location where it was created (or an error object if an error occured). | ||
After the API request is sent to Stripe the full Stripe object is stored at the same location where it was created (or an error object if an error occured). | ||
For child objects i.e. refunds, cards, subscriptions, etc., the reference is deleted after a successful response from Stripe and the parent object i.e. charges, customers, etc. is updated. | ||
@@ -44,3 +45,4 @@ ### StripeFire(key) | ||
```JavaScript | ||
var stripeFire = require("stripe-fire")("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); //sk_test_BQokikJOvBiI2HlWgH4olfQ2 is the example Stripe private key | ||
//sk_test_BQokikJOvBiI2HlWgH4olfQ2 is the example Stripe private key | ||
var stripeFire = require("stripe-fire")("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); | ||
``` | ||
@@ -54,3 +56,8 @@ | ||
```JavaScript | ||
var charges = stripeFire.charges("https://stripe-fire.firebaseio.com/charges", function(err, charge) {}, "ACCESS_TOKEN", function(chargeData, createCharge) { createCharge(chargeData); }); | ||
var charges = stripeFire.charges("https://stripe-fire.firebaseio.com/charges", function(err, charge) { | ||
// Called after a create charge request is sent to Stripe | ||
}, "ACCESS_TOKEN", function(chargeData) { | ||
// Called before a create charge request is sent to Stripe | ||
return chargeData; | ||
}); | ||
``` | ||
@@ -70,7 +77,12 @@ | ||
Initializes a `Refunds` object which is a descendant of the `Charges` object. The charge with the same name as the refund's parent will be retrieved from Stripe and saved under the `Charges` object reference. | ||
Initializes a `Refunds` object which is a descendant of the `Charges` object. The charge with the same name as the refund will be retrieved from Stripe and saved under the `Charges` object reference. | ||
*Example:* | ||
```JavaScript | ||
charges.refunds("https://stripe-fire.firebaseio.com/refunds", function(err, refund) {}, "ACCESS_TOKEN", function(refundData, createRefund) { createRefund(refundData); }); | ||
charges.refunds("https://stripe-fire.firebaseio.com/refunds", function(err, refund) { | ||
// Called after a create refund request is sent to Stripe | ||
}, "ACCESS_TOKEN", function(refundData) { | ||
// Called before a create refund request is sent to Stripe | ||
return refundData; | ||
}); | ||
``` | ||
@@ -82,3 +94,3 @@ | ||
//"ChargeName" should exist as a child in the charges reference | ||
refundsRef.child("ChargeName").push({ | ||
refundsRef.child("ChargeName").set({ | ||
amount: 400 | ||
@@ -88,2 +100,26 @@ }); | ||
### StripeFire.coupons(ref, [callback], [accessToken], [alterRequest]) | ||
Initializes a `Coupons` object. | ||
*Example:* | ||
```JavaScript | ||
stripeFire.coupons("https://stripe-fire.firebaseio.com/coupons", function(err, coupon) { | ||
// Called after a create coupon request is sent to Stripe | ||
}, "ACCESS_TOKEN", function(couponData) { | ||
// Called before a create coupon request is sent to Stripe | ||
return couponData; | ||
}); | ||
``` | ||
*Client-Side Usage:* | ||
```JavaScript | ||
var couponsRef = new Firebase("https://stripe-fire.firebaseio.com/coupons"); | ||
couponsRef.push({ | ||
percent_off: 25, | ||
duration: "repeating", | ||
duration_in_months: 3 | ||
}); | ||
``` | ||
### StripeFire.customers(ref, [callback], [accessToken], [alterRequest]) | ||
@@ -95,3 +131,8 @@ | ||
```JavaScript | ||
var customers = stripeFire.customers('https://your-firebase.firebaseio.com/customers', function(err, customer) {}, 'ACCESS_TOKEN', function(customerData, createCustomer) { createCustomer(customerData); }); | ||
var customers = stripeFire.customers("https://stripe-fire.firebaseio.com/customers", function(err, customer) { | ||
// Called after a create customer request is sent to Stripe | ||
}, "ACCESS_TOKEN", function(customerData) { | ||
// Called before a create customer request is sent to Stripe | ||
return customerData; | ||
}); | ||
``` | ||
@@ -113,3 +154,8 @@ | ||
```JavaScript | ||
customers.cards('https://your-firebase.firebaseio.com/cards', function(err, card) {}, 'ACCESS_TOKEN', function(cardData, createCard) { createCard(cardData); }); | ||
customers.cards("https://stripe-fire.firebaseio.com/cards", function(err, card) { | ||
// Called after a create card request is sent to Stripe | ||
}, "ACCESS_TOKEN", function(cardData) { | ||
// Called before a create card request is sent to Stripe | ||
return cardData; | ||
}); | ||
``` | ||
@@ -121,3 +167,3 @@ | ||
//"CustomerName" should exist as a child in the customers reference | ||
cardsRef.child("CustomerName").push({ | ||
cardsRef.child("CustomerName").set({ | ||
card: "token" | ||
@@ -133,3 +179,8 @@ }); | ||
```JavaScript | ||
customers.subscriptions('https://stripe-fire.firebaseio.com/subscriptions', function(err, subscription) {}, 'ACCESS_TOKEN', function(subscriptionData, createSubscription) { createSubscription(subscriptionData); }); | ||
customers.subscriptions("https://stripe-fire.firebaseio.com/subscriptions", function(err, subscription) { | ||
// Called after a create subscription request is sent to Stripe | ||
}, "ACCESS_TOKEN", function(subscriptionData) { | ||
// Called before a create subscription request is sent to Stripe | ||
return subscriptionData; | ||
}); | ||
``` | ||
@@ -141,5 +192,32 @@ | ||
//"CustomerName" should exist as a child in the customers reference | ||
subscriptionsRef.child("CustomerName").push({ | ||
subscriptionsRef.child("CustomerName").set({ | ||
plan: "plan" | ||
}); | ||
``` | ||
### StripeFire.plans(ref, [callback], [accessToken], [alterRequest]) | ||
Initializes a `Plans` object. | ||
*Example:* | ||
```JavaScript | ||
stripeFire.plans("https://stripe-fire.firebaseio.com/plans", function(err, plan) { | ||
// Called after a create plan request is sent to Stripe | ||
}, "ACCESS_TOKEN", function(planData) { | ||
// Called before a create plan request is sent to Stripe | ||
// IMPORTANT: since id is reserved for retrieving objects this cannot be set in Firebase before being sent to Stripe | ||
plan.id = plan.name; | ||
return planData; | ||
}); | ||
``` | ||
*Client-Side Usage:* | ||
```JavaScript | ||
var plansRef = new Firebase("https://stripe-fire.firebaseio.com/plans"); | ||
plansRef.push({ | ||
amount: 2000, | ||
interval: "month", | ||
name: "name", | ||
currency: "usd" | ||
}); | ||
``` |
@@ -61,3 +61,3 @@ var Firebase = require('firebase'), | ||
}, function () { | ||
ref.child('refunds').child(chargeRef.name()).push({ | ||
ref.child('refunds').child(chargeRef.name()).set({ | ||
amount: 400 | ||
@@ -64,0 +64,0 @@ }, function () { |
@@ -69,3 +69,3 @@ var Firebase = require('firebase'), | ||
}, function(err, token) { | ||
ref.child('cards').child(customersRef.name()).push({ | ||
ref.child('cards').child(customersRef.name()).set({ | ||
card: token.id | ||
@@ -94,2 +94,4 @@ }, function () { | ||
}); | ||
//describe('Subscriptions', function() {}); | ||
}); |
@@ -12,5 +12,13 @@ var Firebase = require('firebase'), | ||
it('should have a coupons property', function() { | ||
stripeFire.should.have.property('coupons'); | ||
}); | ||
it('should have a customers property', function() { | ||
stripeFire.should.have.property('customers'); | ||
}); | ||
it('should have a plans property', function() { | ||
stripeFire.should.have.property('plans'); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2
12
210
25781
363
- Removedfire-child@~0.1.1
- Removedfire-child@0.1.1(transitive)