lib/active_merchant/billing/gateways/securion_pay.rb in activemerchant-1.58.0 vs lib/active_merchant/billing/gateways/securion_pay.rb in activemerchant-1.59.0

- old
+ new

@@ -2,22 +2,14 @@ module Billing #:nodoc: class SecurionPayGateway < Gateway self.test_url = 'https://api.securionpay.com/' self.live_url = 'https://api.securionpay.com/' - self.supported_countries = ["AF", "AL", "DZ", "AS", "AD", "AO", "AI", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", - "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", - "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CW", "CY", "CZ", "DK", "DJ", - "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", - "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", "VA", "HN", "HK", "HU", "IS", "IN", "ID", - "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "KP", "KR", "KV", "KW", "KG", "LA", "LV", "LB", - "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MK", "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", - "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "AN", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MP", - "NO", "OM", "PK", "PW", "PS", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "BL", "SH", - "KN", "LC", "MF", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", "SK", "SI", "SB", "SO", "ZA", "GS", "ES", - "LK", "SD", "SR", "SJ", "SZ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", - "TV", "UG", "UA", "AE", "GB", "US", "UM", "UY", "UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW", "AX"] + + self.supported_countries = %w(AL AD AT BY BE BG HR CY RE DK EE IS FI FR DE GI GR HU IS IE IT LV LI LT LU + MK MT MD MC NL NO PL PT RO RU MA RS SK SI ES SE CH UA KI CI RS RS ME) + self.default_currency = 'USD' self.money_format = :cents self.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb, :diners_club] self.homepage_url = 'https://securionpay.com/' @@ -77,10 +69,33 @@ r.process { authorize(100, credit_card, options) } r.process(:ignore_result) { void(r.authorization, options) } end end + def store(credit_card, options = {}) + if options[:customer_id].blank? + MultiResponse.run() do |r| + #create charge object + r.process { authorize(100, credit_card, options) } + #create customer and save card + r.process { create_customer_add_card(r.authorization, options) } + #void the charge + r.process(:ignore_result) { void(r.params["metadata"]["chargeId"], options) } + end + else + verify(credit_card, options) + end + end + + def customer(options = {}) + if options[:customer_id].blank? + return nil + else + commit("customers/#{CGI.escape(options[:customer_id])}", nil, options, :get) + end + end + def supports_scrubbing? true end def scrub(transcript) @@ -90,12 +105,22 @@ gsub(%r((card\[cvc\]=)\d+), '\1[FILTERED]') end private + def create_customer_add_card(authorization, options) + post = {} + post[:email] = options[:email] + post[:description] = options[:description] + post[:card] = authorization + post[:metadata] = {} + post[:metadata][:chargeId] = authorization + commit('customers', post, options) + end + def add_customer(post, payment, options) - post[:customer] = options[:customer] if options[:customer] + post[:customerId] = options[:customer_id] if options[:customer_id] end def add_customer_data(post, options) post[:description] = options[:description] post[:ip] = options[:ip] @@ -154,12 +179,12 @@ def parse(body) JSON.parse(body) end - def commit(url, parameters = nil, options = {}) - response = api_request(url, parameters, options) + def commit(url, parameters = nil, options = {}, method = nil) + response = api_request(url, parameters, options, method) success = !response.key?("error") Response.new(success, (success ? "Transaction approved" : response["error"]["message"]), response, @@ -204,13 +229,17 @@ "#{key}=#{CGI.escape(value.to_s)}" end end.compact.join("&") end - def api_request(endpoint, parameters = nil, options = {}) + def api_request(endpoint, parameters = nil, options = {}, method = nil) raw_response = response = nil begin - raw_response = ssl_post(self.live_url + endpoint, post_data(parameters), headers(options)) + if method.blank? + raw_response = ssl_post(self.live_url + endpoint, post_data(parameters), headers(options)) + else + raw_response = ssl_request(method, self.live_url + endpoint, post_data(parameters), headers(options)) + end response = parse(raw_response) rescue ResponseError => e raw_response = e.response.body response = response_error(raw_response) rescue JSON::ParserError