activemerchant / active_merchant

Active Merchant is a simple payment abstraction library extracted from Shopify. The aim of the project is to feel natural to Ruby users and to abstract as many parts as possible away from the user to offer a consistent interface across all supported gateways.
http://activemerchant.org
MIT License
4.52k stars 2.49k forks source link

QuickPay: enable recurring payments in v10 #2172

Closed wsmoak closed 7 years ago

wsmoak commented 7 years ago

As I commented on https://github.com/activemerchant/active_merchant/pull/1873, the current implementation of 'store' for QuickPay v10 returns a single-use token.

The existing test demonstrates that you can store and then use it to make a purchase, but if you attempt a second purchase, as for a subscription renewal, it will fail because the token has already been used.

I tested this with the API directly with curl and checked with QuickPay support to confirm that...

Storing a card is:

  1. POST https://api.quickpay.net/cards (no body)
  2. POST https://api.quickpay.net/cards/$CARD_ID/authorize?synchronized (card details)

Now the card is stored and can be reused, so

Creating a payment is:

  1. POST https://api.quickpay.net/cards/$CARD_ID/tokens?synchronized (no body)
  2. POST https://api.quickpay.net/payments (currency, order_id)
  3. POST https://api.quickpay.net/payments/$PAYMENT_ID/authorize?synchronized (amount, token from step 1)
  4. POST https://api.quickpay.net/payments/$PAYMENT_ID/capture?synchronized (amount)

I'll branch and see if I can re-work this. Let me know if anyone else is already working on it or if you have any comments/suggestions!

wsmoak commented 7 years ago

Based on discussion in https://github.com/activemerchant/active_merchant/pull/1873, 'purchase' needs to support both

  1. a single purchase with full card details, and
  2. a recurring purchase using a token

It appears that /payments/:id/authorize takes either a token or the full card info, so this should be possible... http://tech.quickpay.net/api/services/?scope=merchant#POST-payments--id-authorize---format-

wsmoak commented 7 years ago

I've got a fix working for this, but I'm having to dig through the response to find the payment id I need, when based on the existing code I think it should be in 'r.authorization'.

https://github.com/activemerchant/active_merchant/compare/master...chargify:quickpay_recurring

Could someone take a look? Or should I go ahead and open a PR since there is now code to discuss? Thanks! /cc @duff

duff commented 7 years ago

Looks like they don't make it super cinchy to run recurring purchases against a stored card. Tokens, cards, references, auths, captures. Whew! Pretty great that you've got a remote test demonstrating the issue.

👍 for a PR

davidsantoso commented 7 years ago

Closed with ed4ed2d03837a3a7db6a22fc37861c22f3779c90. Thanks for opening up this issue @wsmoak!