-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CheckoutPricing: Coupons #385
Changes from 44 commits
95a861e
e4c5f81
f3be292
e26485d
53b622b
75af47d
0f84178
c513752
2e73e2a
b8df59c
8503c99
b75213f
19f22f9
adb4523
bd08d09
712f670
4430bb4
2a96fa2
06b62b8
73b6e63
0fab807
3860f7f
fcb7da7
c1b7e07
18eca38
576644b
a04476b
59008b8
580312e
b2181c8
2fff200
70b3b98
31a01ed
fbb652c
dc8ecdf
eb0f52f
2aaa800
2c5c70d
8011207
193bb94
2a15d81
1b8eb55
2852800
1bbabe0
2362f17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import Emitter from 'component-emitter'; | ||
import errors from '../errors'; | ||
import {CheckoutPricing} from './pricing/checkout'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this going to be used in one of the followup PR's? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. Prior to writing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #394 |
||
import {SubscriptionPricing} from './pricing/subscription'; | ||
import {normalize} from '../util/normalize'; | ||
import {FIELDS} from './token'; | ||
|
||
const debug = require('debug')('recurly:apple-pay'); | ||
|
||
const SESSION_TIMEOUT = 300000; // 5m | ||
const APPLE_PAY_API_VERSION = 2; | ||
const APPLE_PAY_ADDRESS_MAP = { | ||
first_name: 'givenName', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
var type = require('component-type'); | ||
var debug = require('debug')('recurly:coupon'); | ||
var errors = require('../errors'); | ||
import errors from '../errors'; | ||
|
||
module.exports = coupon; | ||
const debug = require('debug')('recurly:coupon'); | ||
|
||
const CHUNK_SIZE = 100; | ||
|
||
/** | ||
* Coupon mixin. | ||
* | ||
* Retrieves coupon information for the `plan`. The `callback` signature | ||
* is `err, plan` where `err` may be a request or server error, and `plan` | ||
* is a representation of the requested plan. | ||
* Retrieves coupon information for the `coupon` and optional `plan`. | ||
* The `callback` signature is `err, coupon` where `err` may be a request | ||
* or server error, and `coupon` is a representation of the requested coupon. | ||
* | ||
* @param {Object} options | ||
* @param {Function} callback | ||
* @param {String} options.coupon coupon code | ||
* @param {String} [options.plan] plan code | ||
* @param {Array[String]} [options.plans] plan codes | ||
* @param {Function} done | ||
*/ | ||
|
||
function coupon (options, callback) { | ||
export default function coupon (options = {}, done) { | ||
debug('%j', options); | ||
|
||
if ('function' !== type(callback)) { | ||
throw errors('missing-callback'); | ||
} | ||
|
||
if ('object' !== type(options)) { | ||
throw errors('invalid-options'); | ||
} | ||
let {coupon, plans, plan, currency} = options; | ||
|
||
if (!('plan' in options)) { | ||
throw errors('missing-plan'); | ||
} | ||
if (!coupon) throw errors('missing-coupon'); | ||
if (typeof done !== 'function') throw errors('missing-callback'); | ||
|
||
if (!('coupon' in options)) { | ||
throw errors('missing-coupon'); | ||
} | ||
if (!plans && plan) plans = [plan]; | ||
|
||
this.request('get', '/plans/' + options.plan + '/coupons/' + options.coupon, options, callback); | ||
this.pipedRequest({ | ||
method: 'get', | ||
route: `/coupons/${coupon}`, | ||
data: { plan_codes: plans, currency }, | ||
by: 'plan_codes', | ||
size: CHUNK_SIZE, | ||
}).nodeify(done); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about setting the default for
size
here like it appears in the doc block above. Since the only use of this function at this time using the default, we could remove the arg in that call. Is themethod
generally always going to be aGET
? If so, we could set that default as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually fixed the default assignment in #393 when I added specs for this method. I'll add it here too.
+1 to setting the method default as well