kfrancis / chargify-dot-net Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Thanks for putting this project out there. It is making my life much easier right now!
I have an enhancement request.
The chargify REST API will return XML, which is serialized into C# objects, I would like to be able to serialize those objects back to XML that matches the XML returned by the REST API as we'll be storing a copy of this XML in our own system.
Any plans to enhance Chargify.NET to serialize various entity type classes (ProductFamily, Product, Component, Customer, and Subscription) to their XML representation?
Even if there's no plans, I can create this XML myself, but some of the objects do not support all of the properties available in the XML.
I'll post a separate issue for those.
It seem as though this part of the API is not fully implemented...or am I missing something?
https://docs.chargify.com/api-payment-profiles
Thanks in advance!
Endpoints for coupon validation and coupon usage are detailed in the API docs here but don't seem to be available in this library (that I could see): https://docs.chargify.com/api-coupons
Calling PreviewRenewal results in
Unexpected character encountered while parsing value: C. Path '', line 0, position 0.
That's what we get when calling wrapper method - it looks like data structure has changed since wrapper lib was implemented.
/subscriptions/123/components/456.xml is depreciated (doesnt properly honor upgrade/downgrade schemes).
Hi,
Can the purge function be implemented to remove subscriptions?
Using a POST request:
On calling CreateSubscription this exception is always thrown: System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index'. I've included the exception details below.
I'm using version Chargify.Net 1.2.5 from Nuget on a .Net Framework 4.6.1 project, and Newtonsoft.Json v11.0.2.
Here is the code (this is on a test account so I'm passing "1" for the credit card):
CustomerAttributes customer = new CustomerAttributes("Damon", "Janis", "[email protected]", "Quest", "7645");
CreditCardAttributes creditCard = new CreditCardAttributes("Damon", "Janis", "1", 2022, 4, "123", "150 Rainbow Dr #5022", "Livingston", "TX", "77399", "US");
var subscription = ChargifyConnect.CreateSubscription("standard-monthly", customer, creditCard);
I've tried passing in different information but no matter what I try, the same exception is always thrown. Here are the exception details:
System.ArgumentOutOfRangeException
HResult=0x80131502
Message=Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Source=mscorlib
StackTrace:
at System.Collections.ArrayList.get_Item(Int32 index)
at ChargifyNET.Json.XmlToJsonConverter.XmlToJsoNnode(StringBuilder sbJson, XmlElement node, Boolean showNodeName)
at ChargifyNET.Json.XmlToJsonConverter.OutputNode(String childname, Object alChild, StringBuilder sbJson, Boolean showNodeName)
at ChargifyNET.Json.XmlToJsonConverter.XmlToJsoNnode(StringBuilder sbJson, XmlElement node, Boolean showNodeName)
at ChargifyNET.Json.XmlToJsonConverter.XmlToJson(XmlDocument xmlDoc)
at ChargifyNET.ChargifyConnect.DoRequest(String methodString, HttpRequestMethod requestMethod, String postData)
at ChargifyNET.ChargifyConnect.CreateSubscription(String productHandle, String newSystemId, String firstName, String lastName, String emailAddress, String phone, String organization, String vatNumber, String shippingAddress, String shippingCity, String shippingState, String shippingZip, String shippingCountry, String fullNumber, Int32 expirationMonth, Int32 expirationYear, String cvv, String billingAddress, String billingCity, String billingState, String billingZip, String billingCountry, String couponCode, Int32 componentId, Int32 allocatedQuantity)
at ChargifyNET.ChargifyConnect.CreateSubscription(String productHandle, ICustomerAttributes customerAttributes, ICreditCardAttributes creditCardAttributes)
at questBLL.Chargify.CreateCustomer(String firstName, String lastName, String email, String fullNumber, String cvv, Int32 expirationMonth, Int32 expirationYear, String billingAddress, String billingCity, String billingState, String billingZip) in C:\Users\damonjanis\Dropbox\Data\work\Projects\Quest\Src\BLL\Chargify.cs:line 31
at TestBLL.Program.Main(String[] args) in C:\Users\damonjanis\Dropbox\Data\work\Projects\Quest\Src\TestBLL\Program.cs:line 19
It looks like the payment API was added in April, so it needs to be added to the library.
i.e. public ICustomer LoadCustomer(int chargifyId);
This same issue will occur for subscriptions in the future, however at this time they are in the millions.
Hi, when doing a one-time charge, there isn't a setting for taxable. I have done the change in the source code but I am unable to upload it. If you would like it, please tell me what I need to do to get it to you.
Thanks.
So that my client can have certainty that they are not going to have to open source their code base, because they used an AGPL licence library. Can you please provide a licence, that this project can be used under.
Both here and on the nuget page.
In version .5879, PaymentProfile.FullCardNumber is blank (in older releases it wasn't) and Card Type is missing.
Someone committed a fix for this...Can you possibly roll this into the release soon? Thanks!
Hi,
This function is ignoring name from credit card. It just takes name from customer.
CreateSubscription(string ProductHandle, ICustomerAttributes CustomerAttributes, ICreditCardAttributes CreditCardAttributes)
JSON spec explicitly states which characters can be used to denote numbers; Chargify also uses culture-independent settings when outputting JSON and XML. However, chargify-dot-net uses the current thread culture to parse numbers and dates/times both in JSON and XML, and sometimes fails silently when failing to parse JSON or XML.
Tests can be used to enforce 3 conditions:
Incomplete list of affected methods:
In upgrading to the latest version (to fix the bad request issue with customer update) we've been experiencing the following error when trying to run in our hosted environment.
Inheritance security rules violated while overriding member: 'ChargifyNET.ChargifyException.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
Our site is hosted on Rackspace Cloud Sites where they run with Modified Medium Trust.
This seems to have been introduced by the recent update in Chargify.NET to .NET 4+ (Security Changes)
I've researched this problem today and have implemented and tried a few of the suggested fixes for it but I've been unable to fix the issue at this time.
We have need for programatically enabling the billing portal. Chargify supports this (https://reference.chargify.com/v1/billing-portal/enabling-billing-portal-for-customer) but there is no method for this in your API.
It doesn't look that difficult to contribute this myself. If you are unable or unwilling to do it I can try to find the time.
Per the Chargify docs, there is no return_url and return_params; there is only update_return_url and update_return_params
(Interestingly, return_params still seems to be included the the product XML from Chargify, but return_url is not).
I've had a go at fixing this, will submit a PR.
When do you think you be updating the library to support this upcoming change by Chargify?
https://help.chargify.com/announcements/new-chargifypay-domain.html
Thanks!
It looks like I had been checking for uniqueness before creating the subscription and when adding subsequent subscriptions for a customer, this actually prevents it from working correctly.
Allow the GetTransactionList method to specify either descending or ascending.
Let's update the EditSubscriptionProduct
method to allow for delayed product change, which only requires one additional optional paramter.
Same request as for the API v2 SDK: kfrancis/Chargify2#3
The current library only exposes synchronous methods, meaning the web server is forced to keep a CPU thread twiddling its thumbs while waiting for the Chargify response. Since the thread pool is a limited resource, enough traffic to long running synchronous tasks like these can cause a severe bottleneck.
I recommend refactoring to .NET 4.5 async methods (or .NET 4 with microsoft.bcl.async nuget) so they are async by default and can be called synchronously by .Wait or .Result properties if so desired.
I have a subscription for a test site that has 3 custom fields with names and values assigned.
Below is a screenshot showing the custom fields populated for the subscription.
When I call the GetMetadataFor like:
var sub = chargify.LoadSubscription(subId);
var meta = chargify.GetMetadataFor<Subscription>(subId, null);
I do get a MetadataResult object back with 3 items in the Metadata list, but all them have empty strings in the name and value properties. The ResourceID is also just 0 (zero).
Any ideas why this is happening?
The GetPrettySubscriptionUpdateURL is 404'ing because the "/" parts of the URL itself are getting encoded. I haven't been able to narrow down what has changed on chargify's end to cause this - it does seem like a bug in Chargify.NET though. I've outlined fixes below.
If you update the Chargify.NET ChargifyConnect class to the following it should resolve the issue.
public string GetPrettySubscriptionUpdateURL(string firstName, string lastName, int subscriptionId)
{
if (string.IsNullOrEmpty(SharedKey)) throw new ArgumentException("SharedKey is required to generate the hosted page url");
string message = UpdateShortName + "--" + subscriptionId + "--" + SharedKey;
string token = message.GetChargifyHostedToken();
string prettyId = string.Format("{0}-{1}-{2}", subscriptionId, PCLWebUtility.WebUtility.UrlEncode(firstName.Trim().ToLower()), PCLWebUtility.WebUtility.UrlEncode(lastName.Trim().ToLower()));
string methodString = string.Format("{0}/{1}/{2}", UpdateShortName, prettyId, token);
// just in case?
// methodString = PCLWebUtility.WebUtility.UrlEncode(methodString);
string updateUrl = string.Format("{0}{1}{2}", URL, (URL.EndsWith("/") ? "" : "/"), methodString);
return updateUrl;
}
All i've done is comment out the global Urlencode call and wrap first and last name in encodes instead (as I believe those are the 2 potential problem areas - each of the sections could be wrapped in encodes instead). I also believe the URL encode in this method could be removed or modified as deemed appropriate.
Edit: I've looked into making a pull request but There's a billion errors - i think related to nuget packages.. or something... that I can't seem to fix at this time.
Edit 2: I updated the code snippets above - I was looking at the Chargify.NET folder in source - and that's apparently.. no longer.. needed/updated/used? I'm honestly not sure - but these changes are based on the code in the chargifydotnet structure instead.
Edit 3: I defeated VS/Git/TheWorld - PR at #55
The sample app http://chargify.clinicalsupportsystems.com/ does not work.
We have noticed that some ChargifyException Message values contain sensitive information, namely the request body that was posted to chargify. Here is an abridged sample (bogus credit card number used)
[ChargifyException: The server returned 'Unprocessable Entity' with the status code 422 (422) when posting '<?xml version="1.0" encoding="UTF-8"?><subscription><credit_card_attributes><full_number>4111111111111119</full_number><expiration_month>10</expiration_month><expiration_year>2019</expiration_year><cvv>000</cvv><billing_country>NZ</billing_country></credit_card_attributes></subscription>'.]
Some request body values may be acceptable to include in the message but probably not any containing a cc number etc
Happy to have a crack at resolving this issue
Per the chargify API, this is an optional parameter: https://docs.chargify.com/api-subscriptions (scroll to "next_billing_at)
This is actually pretty important in that a null value collects payment immediately / when the subscription is created. If this value is set (event to a date in the past), there's a delay.
Any chance you can change this to be DateTime? in the applicable methods? I'm particularly interested in the one that takes in a paymentProfileID.
PS -- Thanks for adding the payment profile stuff so quickly!!
The Subscription#create API endpoint now takes an optional ref parameter.
https://docs.chargify.com/referrals
https://docs.chargify.com/api-subscriptions
On this one, you are passing the MinValue on both items which causes it to not use them. I have fixed this issue as well, I can upload my changes if you let me.
Thanks... Here is the new source code
As far as I see Microsoft.Net.Compilers is used for development only, but here on nuget I see this dependency:
https://www.nuget.org/packages/chargify/
Microsoft.Net.Compilers (>= 1.1.1)
GetCustomerList(true) was the solution :)
I updated to the latest build on Nuget to implement VatNumber functionality since a PR #15, however I am getting the following error when I try to call my method which gets a customer and updates the VatNumber property - assuming it's not been fully implemented?
System.MissingMethodException was unhandled by user code
Method not found: 'Void ChargifyNET.ICustomerAttributes.set_VatNumber(System.String)'.
Where is IMetafield (referenced by ChargifyConnect class) defined? I did a clean pull and am seeing the following error trying to build (in VS2017):
The type or namespace name 'IMetafield' could not be found (are you missing a using directive or an assembly reference?) ChargifyDotNet(netstandard2.0)
\chargify-dot-net\Source\ChargifyDotNet\ChargifyConnect.cs 215
Chargify are no longer supporting TLS 1.0 and 1.1 from 12 January 2016 (https://docs.chargify.com/tls-upgrade-notice). In my Chargify control panel I saw a notification saying "We’re concerned that your Chargify integration will stop working on Jan 12, 2016. Please see your TLS Check page (https://app.chargify.com/tls_check) for more information."
Sure enough that page shows a that the client 'Chargify.NET Client v1.1.5738.19989' is using TLSv1.
I believe a configuration change is necessary to explicitly set the ChargifyConnect.ProtocolType
to SecurityProtocolType.Tls12
as this is now the only supported protocol. It could be that this is unnecessary and it will switch automatically? But as I couldn't see it documented on the project here I thought I'd ask just in case come D-Day anyone has any issues.
I am working on converting the C# object returned from Chargify.NET back into XML, however, I'm noticing some elements in the XML returned by Charfigy's REST API are not represented as properties in the C# objects.
Example:
Class: Product
Missing: taxable
initial_charge_after_trial
update_return_params
Class: Component:
Supports only 3 properties(id, quantity, memo) , everything else is missing, such as: pricing_scheme, unit_name, unit_price, kind, etc.
Class: Customer/CustomerAttributes
Missing:
portal_customer_created_at
portal_invite_last_sent_at
portal_invite_last_accepted_at
I didn't look @ the Subscription class.
I suspect that they've added new properties over time, and/ore these are non-critical type fields for the most part.
There seems to only be support for getting a list of invoices, while there is no support for adding a payment to an invoice, like described in the Chargify API: https://docs.chargify.com/api-invoices-payments
By just using AddPayment, the payment will not be linked to the invoice and the status will remain Unpaid.
Am I right here, or am I missing something here?
Hey @kfrancis I mentioned this to you via Twitter but thought I would also jump in here and have a go at adding the option myself as my first time working with GitHub. Please let me know if I do anything wrong or don't follow the correct GitHub conventions though 😄
https://docs.chargify.com/api-coupons#api-subscription-coupon-remove
While the API used to allow empty nodes, that has been closed and now causes 500 errors. If there are no updates, there should be no call.
In the private method for updating the subscription credit card, the CVV's length is checked if the CVV is required in Chargify. HOWEVER, it is possible to pass in a null value for the CVV if that value should not be updated. Because there is no check to see if the CVV is null, the call to this method throws a null object reference exception. This bug makes it impossible to update just the billing address from the library.
Are Price Points updatable with the API? I searched code for "price_point_id" and "PricePoint", but didn't get any hits.
If not, are there any plans to add in near future?
Thanks!
Is there currently support for previewing changes to allocations?
As seen in their api here
Hi,
I'm using ChargifyDotNet to check and move configuration changes between sites. Thanks for the excellent work!
I noticed that there is no UpdateProduct method. There is an UpdateCustomer method, and Customers have settable properties - but Products seem to have properties that are get-only.
Is this by design? It seems like the Chargify API allows product updates, so I'm wondering why ChargifyDotNet doesn't.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.