lib/active_merchant/billing/gateways/card_connect.rb in activemerchant-1.79.2 vs lib/active_merchant/billing/gateways/card_connect.rb in activemerchant-1.80.0

- old
+ new

@@ -128,10 +128,25 @@ def verify(credit_card, options = {}) authorize(0, credit_card, options) end + def store(payment, options = {}) + post = {} + add_payment(post, payment) + add_address(post, options) + add_customer_data(post, options) + commit('profile', post) + end + + def unstore(authorization, options = {}) + account_id, profile_id = authorization.split('|') + commit('profile', {}, + verb: :delete, + path: "/#{profile_id}/#{account_id}/#{@options[:merchant_id]}") + end + def supports_scrubbing? true end def scrub(transcript) @@ -173,17 +188,23 @@ post[:orderid] = options[:order_id] post[:ecomind] = (options[:recurring] ? 'R' : 'E') end def add_payment(post, payment) - post[:name] = payment.name - if card_brand(payment) == 'check' - add_echeck(post, payment) + if payment.is_a?(String) + account_id, profile_id = payment.split('|') + post[:profile] = profile_id + post[:acctid] = account_id else - post[:account] = payment.number - post[:expiry] = expdate(payment) - post[:cvv2] = payment.verification_value + post[:name] = payment.name + if card_brand(payment) == 'check' + add_echeck(post, payment) + else + post[:account] = payment.number + post[:expiry] = expdate(payment) + post[:cvv2] = payment.verification_value + end end end def add_echeck(post, payment) post[:accttype] = 'ECHK' @@ -235,22 +256,22 @@ def parse(body) JSON.parse(body) end - def url(action) + def url(action, path) if test? - test_url + action + test_url + action + path else - (@options[:domain] ? @options[:domain] : live_url) + action + (@options[:domain] || live_url) + action + path end end - def commit(action, parameters) + def commit(action, parameters, verb: :put, path: '') parameters[:merchid] = @options[:merchant_id] - url = url(action) - response = parse(ssl_request(:put, url, post_data(parameters), headers)) + url = url(action, path) + response = parse(ssl_request(verb, url, post_data(parameters), headers)) Response.new( success_from(response), message_from(response), response, @@ -269,10 +290,14 @@ def message_from(response) response['setlstat'] ? "#{response['resptext']} #{response['setlstat']}" : response['resptext'] end def authorization_from(response) - response['retref'] + if response['profileid'] + "#{response['acctid']}|#{response['profileid']}" + else + response['retref'] + end end def post_data(parameters = {}) parameters.to_json end