forked from jforrest/Chargify-PHP-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
PHP client for Chargify
Please let me know if you have any questions.
License
andresgz/Chargify-PHP-Client
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Chargify PHP Client library Jason Forrest, 2010 ([email protected]) This is a PHP client for the Chargify API. It allows JSON, XML or internal classes to be used. All calls will raise an exception on error, so make sure to wrap calls in a try...catch block. Also, be sure to check out the Wiki for more tips: http://wiki.github.com/jforrest/Chargify-PHP-Client/ Abraham Williams has created a great Getting Started guide for this library, I recommend you check it out for example usage: http://github.com/abraham/chargify Example XML usage: //assumes $subscription_xml contains xml data. This can be from your app, or //populated from any Chargify Data object (inherits ChargifyBase) by calling the getXML() method. // ex. $subscription_xml = $chargify_subscription->getXML(); $test_mode = false; $request_format = 'XML'; $connector = new ChargifyConnector($test_mode); try { $new_subscription_xml = $connector->requestCreateSubscription($subscription_xml,$request_format); } catch (ChargifyValidationException $cve) { //process error handling code here. echo $cve->getMessage(); } NOTE: all functions in ChargifyConnector whose names begin with 'retrieve' or 'request' return either pure XML or pure JSON, depending on the format of the request. Example JSON usage: //assumes $subscription_json contains json data. This can be from your app, or //populated from any Chargify Data object (inherits ChargifyBase) by calling the getJSON() method. // ex. $subscription_json = $chargify_subscription->getJSON(); $test_mode = false; $request_format = 'JSON'; $connector = new ChargifyConnector($test_mode); try { $new_subscription_json = $connector->requestCreateSubscription($subscription_json,$request_format); } catch (ChargifyValidationException $cve) { //process error handling code here. echo $cve->getMessage(); } Example internal class usage: //Customer creation $test_mode = false; $xml_import = null; //this is useful for populating from API response. $chargify_customer = new ChargifyCustomer(null, $test_mode); $chargify_customer->email = "[email protected]"; $chargify_customer->first_name = "Charles"; $chargify_customer->last_name = "Jones"; $chargify_customer->reference = "123b1j23kjb"; try { $new_customer = $chargify_customer->create(); } catch (ChargifyValidationException $cve) { //process error handling code here. echo $cve->getMessage(); } //Subscription creation //create customer and credit card first $chargify_customer = new ChargifyCustomer(); //defaults to same as above $chargify_customer->email = "[email protected]"; $chargify_customer->first_name = "Charles"; $chargify_customer->last_name = "Jones"; $chargify_customer->reference = "123b1j23kjb"; $chargify_card = new ChargifyCreditCard(); $chargify_card->first_name = "Charles"; $chargify_card->last_name = "Jones"; $chargify_card->full_number = '4111111111111111'; $chargify_card->cvv = '123'; $chargify_card->expiration_month = "02"; $chargify_card->expiration_year = "2011"; $chargify_card->billing_address = "123 any st"; $chargify_card->billing_city = "Anytown"; $chargify_card->billing_state = "CA"; $chargify_card->billing_zip = "55555"; $chargify_card->billing_country = 'US'; $chargify_subscription = new ChargifySubscription(); //$chargify_subscription->customer_attributes is required //(don't confuse with $chargify_subscription->customer.) $chargify_subscription->customer_attributes = $chargify_customer; $chargify_subscription->credit_card_attributes = $chargify_card; //required (See above) $chargify_subscription->product_handle = "your product handle"; //required or product_id. $chargify_subscription->coupon_code = "coupon_code"; //optional try { $new_subscription = $chargify_subscription->create(); } catch (ChargifyValidationException $cve) { //process error handling code here. echo $cve->getMessage(); }
About
PHP client for Chargify
Please let me know if you have any questions.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published