# File lib/active_merchant/billing/gateways/stripe.rb, line 56 56: def capture(money, identification, options = {}) 57: commit("charges/#{CGI.escape(identification)}/capture", {}) 58: end
# File lib/active_merchant/billing/gateways/stripe.rb, line 38 38: def purchase(money, creditcard, options = {}) 39: post = {} 40: 41: add_amount(post, money, options) 42: add_creditcard(post, creditcard, options) 43: add_customer(post, options) 44: add_customer_data(post, options) 45: add_flags(post, options) 46: 47: raise ArgumentError.new("Customer or Credit Card required.") if !post[:card] && !post[:customer] 48: 49: commit('charges', post) 50: end
# File lib/active_merchant/billing/gateways/stripe.rb, line 64 64: def refund(money, identification, options = {}) 65: post = {} 66: 67: post[:amount] = amount(money) if money 68: 69: commit("charges/#{CGI.escape(identification)}/refund", post) 70: end
# File lib/active_merchant/billing/gateways/stripe.rb, line 72 72: def store(creditcard, options={}) 73: post = {} 74: add_creditcard(post, creditcard, options) 75: add_customer_data(post, options) 76: 77: if options[:customer] 78: commit("customers/#{CGI.escape(options[:customer])}", post) 79: else 80: commit('customers', post) 81: end 82: end
# File lib/active_merchant/billing/gateways/stripe.rb, line 95 95: def add_address(post, options) 96: return unless post[:card] && post[:card].kind_of?(Hash) 97: if address = options[:billing_address] || options[:address] 98: post[:card][:address_line1] = address[:address1] if address[:address1] 99: post[:card][:address_line2] = address[:address2] if address[:address2] 100: post[:card][:address_country] = address[:country] if address[:country] 101: post[:card][:address_zip] = address[:zip] if address[:zip] 102: post[:card][:address_state] = address[:state] if address[:state] 103: end 104: end
# File lib/active_merchant/billing/gateways/stripe.rb, line 86 86: def add_amount(post, money, options) 87: post[:amount] = amount(money) 88: post[:currency] = (options[:currency] || currency(money)).downcase 89: end
# File lib/active_merchant/billing/gateways/stripe.rb, line 106 106: def add_creditcard(post, creditcard, options) 107: if creditcard.respond_to?(:number) 108: card = {} 109: card[:number] = creditcard.number 110: card[:exp_month] = creditcard.month 111: card[:exp_year] = creditcard.year 112: card[:cvc] = creditcard.verification_value if creditcard.verification_value? 113: card[:name] = creditcard.name if creditcard.name 114: post[:card] = card 115: 116: add_address(post, options) 117: elsif creditcard.kind_of?(String) 118: post[:card] = creditcard 119: end 120: end
# File lib/active_merchant/billing/gateways/stripe.rb, line 122 122: def add_customer(post, options) 123: post[:customer] = options[:customer] if options[:customer] && !post[:card] 124: end
# File lib/active_merchant/billing/gateways/stripe.rb, line 91 91: def add_customer_data(post, options) 92: post[:description] = options[:email] || options[:description] 93: end
# File lib/active_merchant/billing/gateways/stripe.rb, line 126 126: def add_flags(post, options) 127: post[:uncaptured] = true if options[:uncaptured] 128: end
# File lib/active_merchant/billing/gateways/stripe.rb, line 166 166: def commit(url, parameters, method=:post) 167: raw_response = response = nil 168: success = false 169: begin 170: raw_response = ssl_request(method, LIVE_URL + url, post_data(parameters), headers) 171: response = parse(raw_response) 172: success = !response.key?("error") 173: rescue ResponseError => e 174: raw_response = e.response.body 175: response = response_error(raw_response) 176: rescue JSON::ParserError 177: response = json_error(raw_response) 178: end 179: 180: card = response["card"] || {} 181: avs_code = AVS_CODE_TRANSLATOR["line1: #{card["address_line1_check"]}, zip: #{card["address_zip_check"]}"] 182: cvc_code = CVC_CODE_TRANSLATOR[card["cvc_check"]] 183: Response.new(success, 184: success ? "Transaction approved" : response["error"]["message"], 185: response, 186: :test => !response["livemode"], 187: :authorization => response["id"], 188: :avs_result => { :code => avs_code }, 189: :cvv_result => cvc_code 190: ) 191: end
# File lib/active_merchant/billing/gateways/stripe.rb, line 149 149: def headers 150: @@ua ||= JSON.dump({ 151: :bindings_version => ActiveMerchant::VERSION, 152: :lang => 'ruby', 153: :lang_version => "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})", 154: :platform => RUBY_PLATFORM, 155: :publisher => 'active_merchant', 156: :uname => (RUBY_PLATFORM =~ /linux|darwin/ ? `uname -a 2>/dev/null`.strip : nil) 157: }) 158: 159: { 160: "Authorization" => "Basic " + ActiveSupport::Base64.encode64(@api_key.to_s + ":").strip, 161: "User-Agent" => "Stripe/v1 ActiveMerchantBindings/#{ActiveMerchant::VERSION}", 162: "X-Stripe-Client-User-Agent" => @@ua 163: } 164: end
# File lib/active_merchant/billing/gateways/stripe.rb, line 201 201: def json_error(raw_response) 202: msg = 'Invalid response received from the Stripe API. Please contact support@stripe.com if you continue to receive this message.' 203: msg += " (The raw response returned by the API was #{raw_response.inspect})" 204: { 205: "error" => { 206: "message" => msg 207: } 208: } 209: end
# File lib/active_merchant/billing/gateways/stripe.rb, line 130 130: def parse(body) 131: JSON.parse(body) 132: end
# File lib/active_merchant/billing/gateways/stripe.rb, line 134 134: def post_data(params) 135: params.map do |key, value| 136: next if value.blank? 137: if value.is_a?(Hash) 138: h = {} 139: value.each do |k, v| 140: h["#{key}[#{k}]"] = v unless v.blank? 141: end 142: post_data(h) 143: else 144: "#{key}=#{CGI.escape(value.to_s)}" 145: end 146: end.compact.join("&") 147: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.