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 GET and DELETE... need to explicitly UrlEncode the coupon id #1027

Closed
rmacfadyen opened this issue Oct 11, 2017 · 6 comments
Closed
Assignees

Comments

@rmacfadyen
Copy link

Coupon delete (and get) appear to need to have the coupon code explicitly UrlEncode'd:

I have a coupon defined called "ABC123-1" and the code below is going to delete all coupons. It was failing with StripeException: No such coupon... and poking at it I realized the problem was lack of urlencoding:

var s = new StripeCouponService(ConfigurationManager.AppSettings["StripePrivateKey"]);

var l = s.List();
foreach (var c in l)
{
    // succeeds
    var n = s.Get(System.Net.WebUtility.UrlEncode(c.Id));

    // fails with StripeException: No such coupon
    s.Delete(c.Id);
}

Googling for "stripe.net need to explicitly urlencode id values" didn't return anything useful.

Is it up to the dev to UrlEncode id values, in general, across the entire API?

@remi-stripe
Copy link
Contributor

@rmacfadyen I tried to reproduce and used the exact same coupon id and then some more complex and I was always able to retrieve or delete the coupon without having to URL encode the ID.

Do you have more details about your issue and potentially a simple test case that reproduces the exact issue end to end from coupon creation to deletion? Also, are you sure that you're not on an old version of the library?

@rmacfadyen
Copy link
Author

Ah hah!

The problem turned out to be that when creating the coupon my Id had spaces at the end (eg. "SZIMEK-01{space}{space}" (why the db uses char instead of varchar I refuse to answer on the grounds it may make me look foolish).

So a bit of trimming and things are fine.

However... something's "not right". Why should the API or the client care that there are spaces at the end? I haven't dug down to figure out if it's the API or the client... sorry.

Thanks for pointing me in the right direction :)

@remi-stripe
Copy link
Contributor

@rmacfadyen I think I found the issue. If you create a coupon in the dashboard with spaces at the end, those are simply stripped. On the other hand, if you do it in code, the spaces are kept.

When you try to retrieve the coupon or delete it though, the id is passed in the URL but it's not URL encoded. Because of this fetching the coupon fails.

For now I would recommend that you simply strip your coupon ids so that there are no trailing spaces at the end, which was likely a mistake in the first place. I'll look into fixing this in the library moving forward though it's an involved change so it might take some time.

@rmacfadyen
Copy link
Author

I agree 100%. Trims all around :)

Thanks for the assist!

@remi-stripe
Copy link
Contributor

Okay I started a pull request for this in #1029 though we'll need to apply this to all services.

@ob-stripe
Copy link
Contributor

As of version 15.3.2, all resources with user-settable IDs should now have their IDs properly URL-encoded.

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

3 participants