Error when Creating Customer and Subscription

Oct 16, 2010 at 4:02 PM

I am getting the below error when I try and create a subscription.  Help! 

Here is the code I am using to call it:

ICustomerAttributes cust = new CustomerAttributes(FirstName, LastName, Email, DomainName, CreatedUser.UserID.ToString());

ICreditCardAttributes payInfo = new CreditCardAttributes();
payInfo.FirstName = FirstName;
payInfo.LastName = LastName;
payInfo.ExpirationMonth = ExpirationMonth;
payInfo.ExpirationYear = ExpirationYear;
payInfo.FullNumber = "1";
payInfo.CVV = "123";
payInfo.BillingAddress = "123 Main St.";
payInfo.BillingCity = "New York";
payInfo.BillingCountry = "United States";
payInfo.BillingState = "New York";
payInfo.BillingZip = "90210";

ISubscription newSubscription = Chargify.CreateSubscription(hdnHandle.Value, cust, payInfo);
if (newSubscription == null)
// subscription failure.


The remote server returned an error: (422) Unprocessable Entity.

[WebException: The remote server returned an error: (422) Unprocessable Entity.]   System.Net.HttpWebRequest.GetResponse() +5373789   ChargifyNET.ChargifyConnect.DoRequest(String methodString, HttpRequestMethod requestMethod, String postData) +1342

[ChargifyException: The server returned 'Unprocessable Entity' with the status code 422 (422) when posting '<?xml version="1.0" encoding="UTF-8"?><subscription><product_handle>gold</product_handle><customer_attributes><first_name>Gabriel</first_name><last_name>Fuller</last_name><email></email><organization>dkfksdjfklj</organization><reference>7075</reference></customer_attributes><credit_card_attributes><full_number>1</full_number><expiration_month>1</expiration_month><expiration_year>2010</expiration_year><cvv>123</cvv><billing_address>123 Main St.</billing_address><billing_city>New York</billing_city><billing_state>New York</billing_state><billing_zip>90210</billing_zip><billing_country>United States</billing_country></credit_card_attributes></subscription>'.]   ChargifyNET.ChargifyConnect.DoRequest(String methodString, HttpRequestMethod requestMethod, String postData) +1800   ChargifyNET.ChargifyConnect.CreateSubscription(String ProductHandle, String NewSystemID, String FirstName, String LastName, String EmailAddress, String Organization, String FullNumber, Int32 ExpirationMonth, Int32 ExpirationYear, String CVV, String BillingAddress, String BillingCity, String BillingState, String BillingZip, String BillingCountry, String CouponCode) +2320   ChargifyNET.ChargifyConnect.CreateSubscription(String ProductHandle, ICustomerAttributes CustomerAttributes, ICreditCardAttributes CreditCardAttributes) +369   LandingPages.SignUp.bntContinue_Click(Object sender, EventArgs e) in C:\Users\Gabriel\Documents\Visual Studio 2008\Projects\LandingPages\LandingPages\SignUp.aspx.cs:121   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Oct 16, 2010 at 4:12 PM


Billing country must be ISO 3166-1 Alpha 2 (so, "US" not "United States"). Check out the ChargifyNET.Data namespace, and ChargifyNET.Controls .. I've put in some help in that area for .NET users.

-- Kori

Oct 16, 2010 at 4:17 PM

Although, the documentation also says "This value is merely passed through to the payment gateway. Some gateways require country codes in a specific format. Please check your gateway’s documentation". What gateway are you using in the end? I imagine you're using the chargify test gateway for now, which I know likes it in that format.

-- Kori

Oct 16, 2010 at 4:41 PM

I am just using the Test Gateway for my development. I changed the value to the ISO ("US") but it is still givine me an error.

When I call the below code, it gives me the same error:

ICustomer customer = Chargify.CreateCustomer(FirstName, LastName, Email, org.DomainName, CreatedUser.UserID.ToString());

Chargify.CreateSubscription calls that same CreateCustomer method when I pass in the ICustomerAttribute, right?  So the error must be coming from that call.



Oh and thanks for such a quick response!  I appreciate it!

Oct 16, 2010 at 4:45 PM

I figured out the issue - my email address was not valid... doh!  My bad!  Thanks for the help!

I wish there was more details when errors are found. IE -"Invalid email address" Is that something that can be built into the Wrapper or is that a Chargify issue?

Oct 17, 2010 at 9:00 PM

Still having issues.

I am able to create a Customer, but when I try to create a Subscription for the customer, I get an the below error:

The server returned 'Unprocessable Entity' with the status code 422 (422)

Here is the code I am using:


ICustomerAttributes cust = new CustomerAttributes();
cust.FirstName = "Gabriel";
cust.LastName = "Fuller";
cust.Email = "";
cust.SystemID = "123456";

ICreditCardAttributes payInfo = new CreditCardAttributes();
payInfo.FirstName = "Gabriel";
payInfo.LastName = "Fuller";
payInfo.ExpirationMonth = 12;
payInfo.ExpirationYear = 2011;
payInfo.FullNumber = "4536474477564475";
payInfo.CVV = "123";
payInfo.BillingAddress = "123 Main St.";
payInfo.BillingCity = "New York";
payInfo.BillingCountry = "US";
payInfo.BillingState = "New York";
payInfo.BillingZip = "90210";

    ICustomer customer = Chargify.CreateCustomer(cust.FirstName,cust.LastName,cust.Email,cust.Organization,cust.SystemID);
    ISubscription newSubscription = Chargify.CreateSubscription(ProductHandle, customer.SystemID, payInfo);
catch (Exception ex)
    litMessage.Text = ex.Message;



Here is the XML that is being sent:


		<billing_address>123 Main St.</billing_address>
		<billing_city>New York</billing_city>
		<billing_state>New York</billing_state>


Here is the entire error:

The server returned 'Unprocessable Entity' with the status code 422 (422) when posting '<?xml version="1.0" encoding="UTF-8"?><subscription><product_handle>gold</product_handle><customer_reference>1230</customer_reference><credit_card_attributes><full_number>4536474477564475</full_number><expiration_month>12</expiration_month><expiration_year>2011</expiration_year><cvv>123</cvv><billing_address>123 Main St.</billing_address><billing_city>New York</billing_city><billing_state>New York</billing_state><billing_zip>90210</billing_zip><billing_country>US</billing_country></credit_card_attributes></subscription>'.

Oct 18, 2010 at 2:32 PM

If you are using the Chargify test gateway, you can only submit "1" for successful and "2" for rejected credit card numbers. I copied your code here, and did run into the same exception until I put the card number to "1".

-- Kori

Oct 18, 2010 at 2:57 PM

Weird.  I knew that and I could have sworn that I tried that... I wil check it out when I get back home tonight to see if that works.  Thanks!

Dec 29, 2010 at 12:27 PM
I really hope that you did not post an actual valid credit card number in your XML output post.
Oct 17, 2013 at 6:33 AM
I am getting the same error "The server returned 'Unprocessable Entity' with the status code 422 (422) when posting".

Please let me know if someone found any solution
Oct 17, 2013 at 1:43 PM
That really depends on what your code is doing, can you create a ticket (with the code that generates the 422 error) at and ask for Kori there? I’ll be able to provide the support you need through that channel.
Kori Francis
Lead Software Developer
Clinical Support Systems
P: 613-767-8864
F: 613-280-1520
From: kindlebit
Sent: ‎Thursday‎, ‎October‎ ‎17‎, ‎2013 ‎2‎:‎33‎ ‎AM
To: [email removed]

From: kindlebit

I am getting the same error "The server returned 'Unprocessable Entity' with the status code 422 (422) when posting".

Please let me know if someone found any solution
Oct 17, 2013 at 2:29 PM
@randymorris - It's not valid, doesn't pass the LUHN check.
Oct 17, 2013 at 2:31 PM
Just a reminder, if you don't use the right test card number - you will get a 422 which means it didn't go through because it was declined (or some other gateway issue). For charges, there's no way to see the gateway response yet - but for subscriptions, you should see the attempted signup and gateway request/response to be able to debug those 422's.
May 27, 2015 at 3:11 AM
Edited May 27, 2015 at 4:45 AM
I have nearly identical code and I'm using 1 for the fullnumber and US for the country code and I'm still getting 422 unprocessable entity.
Code is below:

public static bool MakeSubscription ()

        ICustomerAttributes newcustomer = makeNewCustomer();
        ICustomer registeredCustomer = chargify.CreateCustomer(newcustomer.FirstName, newcustomer.LastName, newcustomer.Email, newcustomer.Phone, newcustomer.Organization, newcustomer.SystemID);
        ICreditCardAttributes newcard = makeCreditCardAttributes(newcustomer);
        ISubscription newSubcription = chargify.CreateSubscription("converdiant-subscription", registeredCustomer.SystemID, newcard);

        return false;

    public static ICreditCardAttributes makeCreditCardAttributes(ICustomerAttributes newcustomer)
        Random random = new Random();
        ICreditCardAttributes newcard = new CreditCardAttributes()
            FirstName = newcustomer.FirstName,
            LastName = newcustomer.LastName,
            ExpirationMonth = 1,
            ExpirationYear = 2020,
            FullNumber = "1",
            CVV = "123",
            BillingAddress = "123 Main St.",
            BillingCity = "New York",
            BillingCountry = "US",
            BillingState = "New York",
            BillingZip = "90210"


        return newcard;

    public static ICustomerAttributes makeNewCustomer()
        ICustomerAttributes newcustomer = new CustomerAttributes("Andrew", "Jones", "", "Chargify", Guid.NewGuid().ToString());
        return newcustomer;
here are my chargigy connect settings with valid whatever replacing my stuff
I'm just posting it so the UseJSON = true is a possibility in the error
public static ChargifyConnect chargify = new ChargifyConnect()
        apiKey = "valid key",
        Password = "x",
        URL = "valid url",
        SharedKey = "valid share key",
        UseJSON = true

We are running in test mode and the error is the same unprocessable entity. not sure what is invalid in my submit.

Update: got the error payment profile can not be blank
Can't seem to find a method to create a payment profile before calling on the subscription method.

xml being sent:

<subscription><product_handle>converdiant-subscription</product_handle><customer_reference>2467e9c9-1499-4390-9f07-c1e6d483d9ce</customer_reference><credit_card_attributes><full_number>1</full_number><expiration_month>1</expiration_month><expiration_year>2020</expiration_year><cvv>123</cvv><billing_address>123 Main St.</billing_address><billing_city>New York</billing_city><billing_state>New York</billing_state><billing_zip>90210</billing_zip><billing_country>US</billing_country></credit_card_attributes></subscription>

the api claims that using the credit_card_attributes is fine, but it complains about no payment profile...