Skip to content

Commit

Permalink
Merge pull request #3 from takayukii/feature/charge_capture_false
Browse files Browse the repository at this point in the history
[Enhancement] 仮売上(オーソリ)への対応
  • Loading branch information
ynakajima committed Oct 14, 2016
2 parents cb6f949 + ec93d21 commit dbe460d
Show file tree
Hide file tree
Showing 3 changed files with 384 additions and 2 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,44 @@ client.getCharge(chargeID, function(err, result) {
}
```

## Capture a Charge
``POST https://api.spike.cc/v1/charges/{CHARGE_ID}/capture``

```javascript
var chargeID = '20140609-064331-onjmfi1z5q';

// POST https://api.spike.cc/v1/charges/{CHARGE_ID}/capture
client.captureCharge(chargeID, function(err, result) {
if (!err) {
console.log(result);
}
});
```

#### result example:
```json
{
"id": "20150913-150339-c26bvg57np",
"object": "charge",
"created": 1442156619,
"livemode": false,
"paid": true,
"amount": 1080,
"currency": "JPY",
"refunded": false,
"card": {},
"source": {},
"captured": true,
"refunds": [],
"amount_refunded": null,
"customer": null,
"description": null,
"dispute": null,
"metadata": {},
"statement_description": null
}
```

## Refund a Charge
``POST https://api.spike.cc/v1/charges/{CHARGE_ID}/refund``

Expand Down
26 changes: 25 additions & 1 deletion lib/spike-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ SpikeAPI.prototype.postCharge = function(chargeData, callback) {
currency: '', // Currency billing amount. ['USD'|'JPY']
amount: 0, // Amount of the billing.
card: '', // Token that has been acquired in SPIKE Checkout.
capture: true, // Flag of captureing a charge as real salesrecord
products: [] // Array of Product instance for billing.
}, chargeData);

// validate argments
var isValid = _validateArgs([
'String', 'Number', 'String', 'Array', 'Function'
'String', 'Number', 'String', 'Boolean', 'Array', 'Function'
], [
chargeData.currency,
chargeData.amount,
chargeData.card,
chargeData.capture,
chargeData.products,
callback
]);
Expand All @@ -61,6 +63,7 @@ SpikeAPI.prototype.postCharge = function(chargeData, callback) {
amount: chargeData.amount,
currency: chargeData.currency,
card: chargeData.card,
capture: chargeData.capture,
products: JSON.stringify(chargeData.products)
};
var options = _.assign(this.requestDefaults, {
Expand Down Expand Up @@ -92,6 +95,27 @@ SpikeAPI.prototype.getCharge = function(id, callback) {
this._request('get', url, options, callback);
};

/**
* Capture the charge of specified ID by REST API.
* @param {string} id Charge ID.
* @param {function} callback function(err, result)
**/
SpikeAPI.prototype.captureCharge = function(id, callback) {
// validate argments
var isValid = _validateArgs([
'String', 'Function'
], arguments);

if (isValid !== true) {
return isValid.callback(isValid.err);
}
var url = REST_BASE_URL + 'charges/' + id + '/capture';
var options = this.requestDefaults;

// post API
this._request('post', url, options, callback);
};

/**
* Refund the charge of specified ID by REST API.
* @param {string} id charge id.
Expand Down

0 comments on commit dbe460d

Please sign in to comment.