lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb in activemerchant-1.53.0 vs lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb in activemerchant-1.54.0

- old
+ new

@@ -12,30 +12,30 @@ def initialize(options = {}) requires!(options, :api_key) super end - def purchase(money, credit_card, options = {}) + def purchase(money, credit_card_or_reference, options = {}) MultiResponse.run(true) do |r| r.process { create_payment(money, options) } r.process { - post = authorization_params(money, credit_card, options) + post = authorization_params(money, credit_card_or_reference, options) add_autocapture(post, false) commit(synchronized_path("/payments/#{r.authorization}/authorize"), post) } r.process { - post = capture_params(money, credit_card, options) + post = capture_params(money, credit_card_or_reference, options) commit(synchronized_path("/payments/#{r.authorization}/capture"), post) } end end - def authorize(money, credit_card, options = {}) + def authorize(money, credit_card_or_reference, options = {}) MultiResponse.run(true) do |r| r.process { create_payment(money, options) } r.process { - post = authorization_params(money, credit_card, options) + post = authorization_params(money, credit_card_or_reference, options) commit(synchronized_path("/payments/#{r.authorization}/authorize"), post) } end end @@ -66,20 +66,20 @@ r.process(:ignore_result) { void(r.authorization, options) } end end def store(credit_card, options = {}) - MultiResponse.run(true) do |r| - r.process { create_subscription(options) } - r.process { - authorize_subscription(r.authorization, credit_card, options) - } + MultiResponse.run do |r| + r.process { create_store(options) } + r.process { authorize_store(r.authorization, credit_card, options)} + r.process { create_token(r.authorization, options.merge({id: r.authorization}))} end end def unstore(identification) - commit(synchronized_path "/subscriptions/#{identification}/cancel") + identification = identification.split(";").last + commit(synchronized_path "/cards/#{identification}/cancel") end def supports_scrubbing? true end @@ -95,11 +95,11 @@ def authorization_params(money, credit_card, options = {}) post = {} add_amount(post, money, options) - add_credit_card(post, credit_card) + add_credit_card_or_reference(post, credit_card) add_additional_params(:authorize, post, options) post end @@ -110,29 +110,30 @@ add_additional_params(:capture, post, options) post end - def create_subscription(options = {}) - requires!(options, :currency) + def create_store(options = {}) post = {} - - add_currency(post, nil, options) - add_subscription_invoice(post, options) - commit('/subscriptions', post) + commit('/cards', post) end - def authorize_subscription(identification, credit_card, options = {}) + def authorize_store(identification, credit_card, options = {}) requires!(options, :amount) post = {} add_amount(post, nil, options) - add_credit_card(post, credit_card, options) - add_additional_params(:authorize_subscription, post, options) - commit(synchronized_path("/subscriptions/#{identification}/authorize"), post) + add_credit_card_or_reference(post, credit_card, options) + commit(synchronized_path("/cards/#{identification}/authorize"), post) end + def create_token(identification, options) + post = {} + post[:id] = options[:id] + commit(synchronized_path("/cards/#{identification}/tokens"), post) + end + def create_payment(money, options = {}) post = {} add_currency(post, money, options) add_invoice(post, options) commit('/payments', post) @@ -149,18 +150,20 @@ response = json_error(response) end Response.new(success, message_from(success, response), response, :test => test?, - :authorization => response['id'] + :authorization => authorization_from(response, params[:id]) ) end - def add_subscription_invoice(post, options = {}) - requires!(options, :order_id, :description) - post[:order_id] = options[:order_id] - post[:description] = options[:description] + def authorization_from(response, auth_id) + if response["token"] + "#{response["token"]};#{auth_id}" + else + response["id"] + end end def add_currency(post, money, options) post[:currency] = options[:currency] || currency(money) end @@ -199,15 +202,20 @@ key = key.to_sym post[key] = options[key] if options[key] end end - def add_credit_card(post, credit_card, options = {}) + def add_credit_card_or_reference(post, credit_card_or_reference, options = {}) post[:card] ||= {} - post[:card][:number] = credit_card.number - post[:card][:cvd] = credit_card.verification_value - post[:card][:expiration] = expdate(credit_card) - post[:card][:issued_to] = credit_card.name + if credit_card_or_reference.is_a?(String) + reference = credit_card_or_reference.split(";").first + post[:card][:token] = reference + else + post[:card][:number] = credit_card_or_reference.number + post[:card][:cvd] = credit_card_or_reference.verification_value + post[:card][:expiration] = expdate(credit_card_or_reference) + post[:card][:issued_to] = credit_card_or_reference.name + end end def parse(body) JSON.parse(body) end