-2

I want to integrate recurring payment using Payeezy in codeigniter. I have implement the single time payment using curl and now i want to recurring payment with acknowledgement to update my DB.

  • Can you please show us what you have tried so far and where you are stuck? That makes it easier for us to help you. – Striezel Sep 20 '16 at 18:54
  • Don't know why the downvotes on your question. Seemed like a pretty straight-forward question to me. I would only suggest that you remove the reference to CodeIgniter. What you really need is the process/psuedocode for doing this task. From there, I'm sure you can handle it in any given PHP MVC framework. – Volomike Apr 25 '17 at 08:22

2 Answers2

0

I created a WordPress plugin for Payeezy that also handles recurring. You should be able to use the underlying PHP code for CodeIgniter.

https://wordpress.org/plugins/wp-payeezy-pay/

0

I can explain the process that will get you the least PCI compliance issues, and that's the token-based API.

1. Generate Token in Payment Form

So basically you'll use the Javascript API to generate your authorize token. An authorize token doesn't charge the card. It's for validating the card and returning a token for better PCI compliance. This API source code and explanation is here:

https://github.com/payeezy/payeezy_js

2. Post Form To Your Server for the Curl Call to FirstData

Then, once you have this token, you post it back to your controller file with a standard form post, but remove the name attribute on your credit card number and credit card CVC fields so that these do not post to your server. Note that you'll need to store this data (but not card number and CVC) because on refunds (and subscription cancellations) you'll need to reply back with the last purchase token, cardholder name, card type, card expiration date, amount spent, and currency code. You may wonder why FirstData/PayEezy is asking you to store cardholder name, card type, and card expiration date. Well, there's a perfectly good explanation for that. Your call center may need that detail for troubleshooting an issue over the phone with a customer. Also, you need that for refunds. And, most importantly, if you're doing a recurring subscription payment, your code needs to look at the expiration date ahead of time before charging because the API call will fail if the card is past expiration. Last, because you're not storing the credit card number and credit card validation (CVC) code, you're going to be in stronger PCI compliance.

From there, since you are already familiar with the Curl process for a single-purchase, it's just a minor single field change (transaction_type becomes 'recurring') in the Curl to do the recurring. For anyone not familiar with the Curl process, it's explained here:

https://developer.payeezy.com/payeezy-api/apis/post/transactions-4

Also, for those unfamiliar people, you'll need to read up on how FirstData/PayEezy wants you to send in the Curl request with a special header that includes Content-Type: application/json, apikey, token, Authorization, nonce, and timestamp. You can see more detail about that here:

https://github.com/payeezy/payeezy_direct_API/blob/master/payeezy_php/example/src/Payeezy.php

(What I did to make that code simpler was intercept the Curl calls from that script into a log file so that I could make it much more straightforward in a single function instead of breaking it up into all these little functions. That made it far easier to understand what was going on.)

3. Switching Curl Call for Recurring Payments

So, as you discovered in your Curl call, you saw how to do a one-time purchase by setting the transaction_type to 'purchase'. For doing recurring, you set transaction_type to 'recurring'. You have to do that from the start. So, if I'm selling something for $29.99 monthly, the very first month charge needs to still be set to type 'recurring', as would any subsequent month.

4. Your Responsibilities for Recurring Payments

Now, this is where everyone gets hung up because it's poorly documented unless you check the PayEezy Developer Support Forum. For subscriptions, PayEezy doesn't have a system for setting payment plans with varying durations, nor setting up automatic (set-it-and-forget-it) subscriptions for you. (I think I read that they have something experimental on Apple Pay, but nothing else yet.) So, to achieve this, you have 2 choices:

  1. Use Chargify.com. Unfortunately, though, this increases CPA (Cost Per Acquisition) of your product or service. You'll have to factor that in if you want to use that. This basically is a SaaS service that you send the transaction to and they handle the automatic subscription plan for you against FirstData/PayEezy.

  2. Roll your own cron job solution. To do this, you basically take the Curl code for a single transaction, and change the transaction type from 'purchase' to 'recurring'. (Do that from the start -- don't start with 'purchase' on a recurring charge.) From there, it's up to you with your own cron job to check for product or service expiration terms, and then send the API call back off to FirstData/PayEezy for charging that card again with the 'recurring' transaction_type.

On either of those options, the customer never gets asked to enter in credit card data past the first time unless their card expires or unless you have some problem billing that card (like insufficient funds).

Of course, doing your own cron job route for the recurring payment has implications you'll need to prepare for:

  • Add some failsafe code so that you prevent the possibility of duplicate transactions, such as a database field.

  • Add some failsafe code such that if you have cancelled a subscription, you won't charge them again.

  • Add some failsafe code such that if they cancel their subscription, yet purchase it again as a subscription at a later time, that you do charge them again and don't block it from your other failsafe code.

  • Add some sort of grace period on your product or service such that even if you "say" that the term expired, you have like a 2 day grace period so that your API has a chance to do a renewal.

  • It's probably a good idea to email the customer before their renewal period so that they can make certain they have money in their account and have a way to cancel that charge (like call your office or call center, or have a link to click where you provide a way to cancel).

  • If their card has expired before the renewal, and you detect that in the warning email that comes before renewal, then you'll want to let them know this.

  • If their card has been declined for any reason at the point of renewal, then you'll want to let them know this and give them a link to go through the cart again to buy it again, or some other way to save that transaction in your code.

How To Do Subscription Cancellations / Stop Recurring Payments

To stop a recurring payment, you treat it just like a refund on a single purchase, but use the transaction ID of the last purchase. This is documented with this Curl example here:

https://developer.payeezy.com/payeezy-api/apis/post/transactions/%7Bid%7D-0

Look under "Refund" and choose Token.

Community
  • 1
  • 1
Volomike
  • 23,743
  • 21
  • 113
  • 209