Skip to content

Commit

Permalink
Merge pull request stripe#40 from Dashlane/master
Browse files Browse the repository at this point in the history
Add support for charges.capture
  • Loading branch information
abh committed Apr 3, 2013
2 parents 1d24ba5 + c0bd403 commit c1830d9
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ All methods takes a callback as their last parameter. The callback is
called with a Javascript `Error` (if any) and then the response.

* `stripe.charges` - create, retrieve, refund and list charges
* `.capture(charge_id, data)` - [capture a charge](https://stripe.com/docs/api#charge_capture), takes the optional parameter data (amount, application_fee)
* `.create(charge)` - [create a charge](https://stripe.com/docs/api#create_charge)
* `.retrieve(charge_id)` - [retrieve a charge](https://stripe.com/docs/api#retrieve_charge) by charge id
* `.refund(charge_id, amount)` - [refund a given charge](https://stripe.com/docs/api#refund_charge), amount in cents
Expand Down
7 changes: 7 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ module.exports = function (api_key, options) {

return {
charges: {
capture: function (charge_id, data, cb) {
if (typeof data === 'function') {
cb = data;
data = {};
}
post("/v1/charges/" + charge_id + "/capture", data, cb);
},
create: function (data, cb) {
post("/v1/charges", data, cb);
},
Expand Down
75 changes: 74 additions & 1 deletion test/charges.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,79 @@ vows.describe("Charges API").addBatch({
},
},
},
'Create an uncaptured charge' : {
topic: function() {
stripe.charges.create({
amount: "50",
capture: false,
currency: "usd",
card: { number: "4242424242424242",
exp_month: 12,
exp_year: 2020,
name: "T. Ester"
}
}, this.callback);
},
'returns an uncaptured charge' : function(err, response) {
assert.isNull(err);
assert.isDefined(response);
assert.equal(response.object, 'charge');
assert.isDefined(response.id);
assert.equal(response.captured, false);
assert.equal(response.uncaptured, true);
},
'Capture a charge fully' : {
topic: function(create_err, charge) {
stripe.charges.capture(charge.id, this.callback);
},
'Got a charge' : function(err, response) {
assert.isNull(err);
assert.isDefined(response);
assert.equal(response.object, 'charge');
assert.isDefined(response.id);
assert.equal(response.amount_refunded, 0);
assert.equal(response.captured, true);
assert.equal(response.uncaptured, false);
}
}
},

'Create an other uncaptured charge' : {
topic: function() {
stripe.charges.create({
amount: "100",
capture: false,
currency: "usd",
card: { number: "4242424242424242",
exp_month: 12,
exp_year: 2020,
name: "T. Ester"
}
}, this.callback);
},
'returns an uncaptured charge' : function(err, response) {
assert.isNull(err);
assert.isDefined(response);
assert.equal(response.object, 'charge');
assert.isDefined(response.id);
assert.equal(response.captured, false);
assert.equal(response.uncaptured, true);
},
'Capture part of a charge' : {
topic: function(create_err, charge) {
stripe.charges.capture(charge.id, {amount: 50}, this.callback);
},
'Got a charge' : function(err, response) {
assert.isNull(err);
assert.isDefined(response);
assert.equal(response.object, 'charge');
assert.isDefined(response.id);
assert.equal(response.amount_refunded, 50);
assert.equal(response.captured, true);
assert.equal(response.uncaptured, false);
}
}
},
'Charge list' : {
topic: function() {
stripe.charges.list({}, this.callback);
Expand All @@ -60,4 +133,4 @@ vows.describe("Charges API").addBatch({
assert.isNumber(response.count);
},
}
}).export(module, {error: false});
}).export(module, {error: false});

0 comments on commit c1830d9

Please sign in to comment.