-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
95a861e
Adds CheckoutPricing#coupon
chrissrogers e4c5f81
Adds CheckoutPricing discount calculations
chrissrogers f3be292
Updates recurly.coupon for new endpoint
chrissrogers e26485d
Removes component-type
chrissrogers 53b622b
Updates coupon module structure
chrissrogers 75af47d
Updates CheckoutPricing for new coupon getter
chrissrogers 0f84178
Updates coupon specs for new endpoint
chrissrogers c513752
Adds recurly.pipedRequest
chrissrogers 2e73e2a
Adds multiple plan code support to coupon getter
chrissrogers b8df59c
Fixes argument syntax
chrissrogers 8503c99
Updates CheckoutPricing coupon handler for new types
chrissrogers b75213f
Improves recurly.pipedRequest response handling
chrissrogers 19f22f9
Adds spec plans
chrissrogers adb4523
Updates SubscriptionPricing.coupon to receive objects
chrissrogers bd08d09
Fixes CheckoutPricing plan currency handling
chrissrogers 712f670
Fixes CheckoutPricing/Calculations sub calculation safety
chrissrogers 4430bb4
Adds EmbeddedSubscriptionPricing
chrissrogers 2a96fa2
Fixes SubscriptionPricing reprice safety
chrissrogers 06b62b8
Fixes CheckoutPricing/Calculations trial detection
chrissrogers 73b6e63
Ensures subscription safety in CheckoutPricing/Calculations
chrissrogers 0fab807
Applies Promise pattern to CheckoutPricing/Calculations
chrissrogers 3860f7f
Fixes checkout pricing free trial coupon application
chrissrogers fcb7da7
Adds adjustment code uniqueness validator
chrissrogers c1b7e07
Adds reprice silence option
chrissrogers 18eca38
Narrows scope of reprice event silencer
chrissrogers 576644b
Fixes itemization collector for checkouts with sub discounts
chrissrogers a04476b
Documentation
chrissrogers 59008b8
Cleans up unused variables
chrissrogers 580312e
Fixes CheckoutPricing/Calculations plan-specific discount filter
chrissrogers b2181c8
Fixes coupon specs
chrissrogers 2fff200
Fixes SubscriptionPricing.reprice
chrissrogers 70b3b98
Adds coupon validity detection for new endpoint
chrissrogers 31a01ed
Fixes coupon fixtures
chrissrogers fbb652c
Fixes coupon validity method safety
chrissrogers dc8ecdf
Fixes pipedRequest for empty sets
chrissrogers eb0f52f
Fixes CheckoutPricing.coupon set and calculations
chrissrogers 2aaa800
Adds CheckoutPricing.coupon specs
chrissrogers 2c5c70d
Fixes CheckoutPricing fixed amount discount overrun
chrissrogers 8011207
Fixes CheckoutPricing subscription coupon and gift card removal
chrissrogers 193bb94
Adds decimalize pass to CheckoutPricing
chrissrogers 2a15d81
Adds CheckoutPricing fixed amount discount soecs
chrissrogers 1b8eb55
Fixes CheckoutPricing free trial application reprice
chrissrogers 2852800
Fixes SubscriptionPricing fixed amount discounting of setup fees
chrissrogers 1bbabe0
Adds CheckoutPricing discount specs
chrissrogers 2362f17
Adds recurly.pipedRequest defaults
chrissrogers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
@@ -1,38 +1,34 @@ | ||
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'); | ||
|
||
/** | ||
* 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'); | ||
} | ||
let {coupon, plans, plan, currency} = options; | ||
|
||
if ('object' !== type(options)) { | ||
throw errors('invalid-options'); | ||
} | ||
if (!coupon) throw errors('missing-coupon'); | ||
if (typeof done !== 'function') throw errors('missing-callback'); | ||
|
||
if (!('plan' in options)) { | ||
throw errors('missing-plan'); | ||
} | ||
if (!plans && plan) plans = [plan]; | ||
|
||
if (!('coupon' in options)) { | ||
throw errors('missing-coupon'); | ||
} | ||
|
||
this.request('get', '/plans/' + options.plan + '/coupons/' + options.coupon, options, callback); | ||
this.pipedRequest({ | ||
route: `/coupons/${coupon}`, | ||
data: { plan_codes: plans, currency }, | ||
by: 'plan_codes' | ||
}).nodeify(done); | ||
} |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Prior to writing the
CheckoutPricing/Attachment
class, I'll adapt these modules to use thePricing
base classThere 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.
See #394