Skip to content
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

Coupon's coupon_code gets overwritten with value of id #89

Open
codynguyen opened this issue Feb 21, 2019 · 1 comment
Open

Coupon's coupon_code gets overwritten with value of id #89

codynguyen opened this issue Feb 21, 2019 · 1 comment

Comments

@codynguyen
Copy link

Hi,

I noticed coupon_code returned from coupon.fetch has the value of id and not of the coupon code. I think it's because coupon_code is used as the idField for the Coupon model (here).

var coupon = recurly.Coupon();
coupon.coupon_code = 'off20';

coupon.fetch(function(err, response) {
  if (err) return res.status(400).json(err);

  console.assert(response.coupon_code, 'off20'); // false
});

I think this piece is responsible. It looks like when setting id (in . inflate()), the value of id is also assigned to the idField, which is coupon_code.

@codynguyen
Copy link
Author

A workaround I'm using is to reset the id setter:

var coupon = recurly.Coupon();
coupon.coupon_code = 'off20';

// Reset the id setter so it does not automatically assigns its value to coupon_code.
coupon.__defineSetter__('id', function() {});

coupon.fetch(function(err, response) {
  if (err) return res.status(400).json(err);

  console.assert(response.coupon_code, 'off20'); // true now
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant