0

I am using Chargify API (https://github.com/jforrest/Chargify-PHP-Client/), we have customers in thousands with monthly subscription, so they charged on their specific dates, i am using a cron which checks subscriptions on daily basis

Problem is we miss a subscription if it could not charged on date which suppose to be charged. Some time customer card could not charged due to no funds in their account or any reason happened with their cards which causes few days delay.

I want to know when a customer card charged in chargify so i can generate a new order that time, i have used above PHP Library but could not found a function which get me info.

Can any one help for this or any other solution to fix this ?

Thanks

Naveed Metlo
  • 375
  • 2
  • 6
  • 18

3 Answers3

1

Chargify has a feature specifically this called "Webhooks" (just like Paypal, Stripe, etc). Whenever there is activity on a customer's subscription (like a monthly renewal), Chargify will send a POST request directly to your server to alert you to it.

The specific documentation is here: https://docs.chargify.io/webhooks

No cron job necessary!

Drew Blas
  • 3,028
  • 1
  • 21
  • 11
  • Yes Drew you are right, i was also reading it but could not found any example in PHP to make it functional for me. Can you please guide me how to make a webhook and use it ? Thanks – Naveed Metlo May 02 '14 at 19:01
  • I don't know for sure, but Googling resulted in these two hits at the very top. They look very promising: https://github.com/lewsid/chargify-webhook-helper https://github.com/crucialwebstudio/Chargify-Sample-App/blob/master/app/controllers/WebhookController.php – Drew Blas May 02 '14 at 19:11
1

You can setup by webhook and get all the information immediately once customer charged and for that you need to setup webhook url on your server and then add it to chargify account, after login go to Settings -> Webhooks -> Add url for example:

http://www.domain.com/webhooks/

Create index.php file under "webhooks" directory and you will be getting an array from chargify like this:

Array
(
    [id] => 29660474
    [event] => renewal_success
    [payload] => Array
        (
            [subscription] => Array
                (
                    [activated_at] => 2014-12-12 06:11:51 -0500
                    [balance_in_cents] => 1900
                    [cancel_at_end_of_period] => false
                    [canceled_at] => 
                    [cancellation_message] => 
                    [created_at] => 2014-12-12 06:11:40 -0500
                    [current_period_ends_at] => 2015-02-12 06:11:40 -0500
                    [expires_at] => 
                    [id] => 7231335
                    [next_assessment_at] => 2015-02-12 06:11:40 -0500
                    [payment_collection_method] => automatic
                    [snap_day] => 
                    [state] => active
                    [trial_ended_at] => 
                    [trial_started_at] => 
                    [updated_at] => 2015-01-12 06:22:21 -0500
                    [current_period_started_at] => 2015-01-12 06:11:40 -0500
                    [previous_state] => active
                    [signup_payment_id] => 78110242
                    [signup_revenue] => 19.00
                    [delayed_cancel_at] => 
                    [coupon_code] => 
                    [total_revenue_in_cents] => 1900
                    [product_price_in_cents] => 1900
                    [product_version_number] => 6
                    [payment_type] => credit_card
                    [customer] => Array
                        (
                            [address] => xx xxxx place Success
                            [address_2] => 
                            [city] => Perth
                            [country] => AU
                            [created_at] => 2014-12-12 06:11:39 -0500
                            [email] => xxxxxxx@hotmail.com
                            [first_name] => Jay
                            [id] => 7093037
                            [last_name] => Gable
                            [organization] => Large
                            [phone] => xxxxxxxx
                            [portal_customer_created_at] => 2014-12-12 06:11:52 -0500
                            [portal_invite_last_accepted_at] => 
                            [portal_invite_last_sent_at] => 
                            [reference] => 548acd6a8ef3a
                            [state] => WA
                            [updated_at] => 2014-12-12 06:11:52 -0500
                            [verified] => false
                            [zip] => 6164
                        )
                    [product] => Array
                        (
                            [accounting_code] => 
                            [archived_at] => 
                            [created_at] => 2014-08-11 03:27:20 -0400
                            [description] => xxxx
                            [expiration_interval] => 
                            [expiration_interval_unit] => never
                            [handle] => monthly-subscription
                            [id] => 3493985
                            [initial_charge_in_cents] => 
                            [interval] => 1
                            [interval_unit] => month
                            [name] => 1 Pair Monthly
                            [price_in_cents] => 1900
                            [request_credit_card] => true
                            [require_credit_card] => true
                            [return_params] => 
                            [return_url] => 
                            [taxable] => false
                            [trial_interval] => 
                            [trial_interval_unit] => month
                            [trial_price_in_cents] => 
                            [update_return_url] => 
                            [updated_at] => 2014-12-11 17:09:41 -0500
                            [product_family] => Array
                                (
                                    [accounting_code] => 
                                    [description] => Standard Monthly Subscriptions
                                    [handle] => monthly-subscription
                                    [id] => 421701
                                    [name] => Australia
                                )
                            [public_signup_pages] => Array
                                (
                                    [id] => 100806
                                    [url] => xx
                                )
                        )
                    [credit_card] => Array
                        (
                            [billing_address] => xxxxx Success
                            [billing_address_2] => 
                            [billing_city] => Perth
                            [billing_country] => AU
                            [billing_state] => WA
                            [billing_zip] => 6164
                            [card_type] => master
                            [current_vault] => braintree_blue
                            [customer_id] => 7093037
                            [customer_vault_token] => 
                            [expiration_month] => 2
                            [expiration_year] => 2015
                            [first_name] => XXXX
                            [id] => 4693476
                            [last_name] => Gable
                            [masked_card_number] => XXXX-XXXX-XXXX-xxxx
                            [vault_token] => xxxxxx
                            [payment_type] => credit_card
                        )
                )
            [site] => Array
                (
                    [id] => xxxxx
                    [subdomain] => xxxxx
                )
        )
)

I hope this helps.

Naveed Metlo
  • 206
  • 1
  • 2
  • 10
0

Easiest way would be to store last successful transaction date in DB and check frequently if a month has passed since last update with cron or mysql events scheduler, never used chargify but paypal api can communicate with your server and return status of transaction, which you can use on your site to update DB

bart
  • 198
  • 1
  • 8
  • I think you didn't read my question fully, i am alreading saving transaction Date in DB. Issue is to get know through cron if any transaction happened on chargify server....? – Naveed Metlo May 01 '14 at 09:34
  • sorry, yes you right, but the point is to save a date of Successful transaction after receiving confirmation from chargify api. As far as I'm aware you can not use your cron to scan someone else server!!! – bart May 01 '14 at 09:41
  • There must be a trigger or notification or response any thing must be to get know about transaction. I think i should ask Chargify support – Naveed Metlo May 01 '14 at 09:53
  • That would be the best way to go , maybe they can guide u through the process, good luck. – bart May 01 '14 at 09:57