-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the PaymentMethod resource
- Loading branch information
1 parent
f5a2f49
commit 30dd739
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
var StripeResource = require('../StripeResource'); | ||
var stripeMethod = StripeResource.method; | ||
|
||
module.exports = StripeResource.extend({ | ||
|
||
path: 'payment_methods', | ||
includeBasic: ['create', 'list', 'retrieve', 'update'], | ||
|
||
attach: stripeMethod({ | ||
method: 'POST', | ||
path: '{paymentMethodId}/attach', | ||
urlParams: ['paymentMethodId'], | ||
}), | ||
|
||
detach: stripeMethod({ | ||
method: 'POST', | ||
path: '{paymentMethodId}/detach', | ||
urlParams: ['paymentMethodId'], | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
'use strict'; | ||
|
||
var stripe = require('../../testUtils').getSpyableStripe(); | ||
var expect = require('chai').expect; | ||
|
||
describe('PaymentMethods Resource', function() { | ||
describe('retrieve', function() { | ||
it('Sends the correct request', function() { | ||
stripe.paymentMethods.retrieve('pm_123'); | ||
expect(stripe.LAST_REQUEST).to.deep.equal({ | ||
method: 'GET', | ||
url: '/v1/payment_methods/pm_123', | ||
headers: {}, | ||
data: {}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('create', function() { | ||
it('Sends the correct request', function() { | ||
var data = { | ||
type: 'card', | ||
card: { | ||
token: 'tok_123', | ||
}, | ||
}; | ||
stripe.paymentMethods.create(data); | ||
expect(stripe.LAST_REQUEST).to.deep.equal({ | ||
method: 'POST', | ||
url: '/v1/payment_methods', | ||
headers: {}, | ||
data: data, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('list', function() { | ||
it('Sends the correct request', function() { | ||
stripe.paymentMethods.list({customer: 'cus_123'}); | ||
expect(stripe.LAST_REQUEST).to.deep.equal({ | ||
method: 'GET', | ||
url: '/v1/payment_methods', | ||
headers: {}, | ||
data: {customer: 'cus_123'}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('update', function() { | ||
it('Sends the correct request', function() { | ||
var data = { | ||
metadata: {key: 'value'}, | ||
}; | ||
stripe.paymentMethods.update('pm_123', data); | ||
expect(stripe.LAST_REQUEST).to.deep.equal({ | ||
method: 'POST', | ||
url: '/v1/payment_methods/pm_123', | ||
headers: {}, | ||
data: data, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('attach', function() { | ||
it('Sends the correct request', function() { | ||
stripe.paymentMethods.attach('pm_123', {customer: 'cus_123'}); | ||
expect(stripe.LAST_REQUEST).to.deep.equal({ | ||
method: 'POST', | ||
url: '/v1/payment_methods/pm_123/attach', | ||
headers: {}, | ||
data: {customer: 'cus_123'} | ||
}); | ||
}); | ||
}); | ||
|
||
describe('detach', function() { | ||
it('Sends the correct request', function() { | ||
stripe.paymentMethods.detach('pm_123'); | ||
expect(stripe.LAST_REQUEST).to.deep.equal({ | ||
method: 'POST', | ||
url: '/v1/payment_methods/pm_123/detach', | ||
headers: {}, | ||
data: {} | ||
}); | ||
}); | ||
}); | ||
}); |