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

Parse incorrectly shaped validation errors #298

Merged
merged 1 commit into from
Feb 24, 2017

Conversation

bhelx
Copy link
Contributor

@bhelx bhelx commented Jan 18, 2017

Resolves #284
Resolves #281

Some coupon validation errors are shaped like normal field errors, for instance:

<?xml version="1.0" encoding="UTF-8"?>
<error>
  <symbol>subscription_must_change</symbol>
  <description>You must change the subscription in order to redeem a coupon.</description>
</error>

instead of what would be expected:

<?xml version="1.0" encoding="UTF-8"?>
<errors>
  <error field="subscription.coupon_code" symbol="subscription_must_change">You must change the subscription in order to redeem a coupon.</error>
</error>

Example code:

$active_subscription = '3b1c9a5c19f46a8e205abe409ebe3c01';

try {
  $subscription = Recurly_Subscription::get($active_subscription);
  $subscription->coupon_code = 'j32yaysm6g';

  $subscription->quantity = 2;
  $subscription->updateImmediately();

  print var_dump($subscription);
} catch (Recurly_ValidationError $e) {
  // prints all the error messages summed up
  print $e->getMessage() . "\n"; // You must change the subscription in order to redeem a coupon.

  // you can also dig through the individual errors, in this case there is only one
  foreach ($e->errors as $fieldErr) {
    print $fieldErr->symbol . "\n"; // subscription_must_change
    print $fieldErr->description . "\n"; // You must change the subscription in order to redeem a coupon.
  }
}

@bhelx bhelx added the WIP label Jan 18, 2017
@bhelx bhelx requested a review from drewish January 18, 2017 22:44
@bhelx bhelx changed the title [WIP] Parse incorrectly shaped validation errors Parse incorrectly shaped validation errors Feb 13, 2017
@bhelx bhelx removed the WIP label Feb 13, 2017
@drewish drewish merged commit b217d6b into master Feb 24, 2017
@drewish drewish deleted the parse_incorrectly_shaped_validation_errors branch February 24, 2017 23:02
@bhelx bhelx mentioned this pull request Mar 21, 2017
@bhelx bhelx added the V2 V2 Client label Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V2 V2 Client
Projects
None yet
2 participants