NullReferenceException on AddCoupon

Apr 23, 2012 at 8:29 PM
Edited Apr 23, 2012 at 8:32 PM
I'm using the following to add a coupon to a Chargify subscription, but I'm getting a NullReferenceException on cc.AddCoupon (cc is a ChargifyConnect)
if (couponCode != null)
    cc.AddCoupon(subscription.SubscriptionID, couponCode);
couponCode is not null, and not empty, but I'm getting a NullReferenceException thrown inside of that method somewhere.
Here's the stacktrace...any ideas?
   at ChargifyNET.ChargifyConnect.DoRequest(String methodString, HttpRequestMethod requestMethod, String postData)
   at ChargifyNET.ChargifyConnect.AddCoupon(Int32 SubscriptionID, String CouponCode) 
   at RedactedNamespace.Billing.ChargifyBilling.AddCoupon(int subscriptionId, string couponCode)
Apr 25, 2012 at 6:25 PM

Interestingly enough, the issue that caused this is that no PostData is sent to the Api from this library.

The line that needs to be changed is:

if (!hasWritten)

And the new line should be:

if (!hasWritten && postData != null)

This edit it made in ChargifyConnect.cs at line 3639

Coordinator
May 17, 2012 at 8:29 PM

I've fixed this in the latest version. Sorry about that. I'll be working on adding unit testing to both frameworks soon.

May 20, 2013 at 12:37 PM
Can anyone send me a complete c#.net code for Create subscription with Coupon.

I have already implemented the subscription creation and using authorize.net as payment getway with chargify. All works fine. But the new requirement is a 10% discount coupon to every customer for first subscription. I have already created a coupon in Charity but didn't found any suitable code. Please also give some input about how we give the coupon code to the customer.

Thanks in advance for any help.
May 23, 2013 at 2:21 PM
djbyter wrote:
I've fixed this in the latest version. Sorry about that. I'll be working on adding unit testing to both frameworks soon.
Can anyone send me a complete c#.net code for Create subscription with Coupon.

I have already implemented the subscription creation and using authorize.net as payment getway with chargify. All works fine. But the new requirement is a 10% discount coupon to every customer for first subscription. I have already created a coupon in Charity but didn't found any suitable code. Please also give some input about how we give the coupon code to the customer.

Thanks in advance for any help.
May 23, 2013 at 2:21 PM
pwilt wrote:
I'm using the following to add a coupon to a Chargify subscription, but I'm getting a NullReferenceException on cc.AddCoupon (cc is a ChargifyConnect) if (couponCode != null) cc.AddCoupon(subscription.SubscriptionID, couponCode); couponCode is not null, and not empty, but I'm getting a NullReferenceException thrown inside of that method somewhere. Here's the stacktrace...any ideas?    at ChargifyNET.ChargifyConnect.DoRequest(String methodString, HttpRequestMethod requestMethod, String postData)    at ChargifyNET.ChargifyConnect.AddCoupon(Int32 SubscriptionID, String CouponCode)    at RedactedNamespace.Billing.ChargifyBilling.AddCoupon(int subscriptionId, string couponCode)
Can anyone send me a complete c#.net code for Create subscription with Coupon.

I have already implemented the subscription creation and using authorize.net as payment getway with chargify. All works fine. But the new requirement is a 10% discount coupon to every customer for first subscription. I have already created a coupon in Charity but didn't found any suitable code. Please also give some input about how we give the coupon code to the customer.

Thanks in advance for any help.