# File lib/active_merchant/billing/gateways/worldpay.rb, line 39 39: def capture(money, authorization, options = {}) 40: response = MultiResponse.new 41: response << inquire(authorization, options) unless options[:authorization_validated] 42: response << commit('capture', build_capture_request(money, authorization, options)) if response.success? 43: response 44: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 27 27: def purchase(money, payment_method, options = {}) 28: response = MultiResponse.new 29: response << authorize(money, payment_method, options) 30: response << capture(money, response.authorization, :authorization_validated => true) if response.success? 31: response 32: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 53 53: def refund(money, authorization, options = {}) 54: response = MultiResponse.new 55: response << inquire(authorization, options) 56: response << commit('refund', build_refund_request(money, authorization, options)) if response.success? 57: response 58: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 46 46: def void(authorization, options = {}) 47: response = MultiResponse.new 48: response << inquire(authorization, options) 49: response << commit('cancel', build_void_request(authorization, options)) if response.success? 50: response 51: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 164 164: def add_address(xml, element, address) 165: return if address.nil? 166: 167: xml.tag! element do 168: xml.tag! 'address' do 169: if m = /^\s*([^\s]+)\s+(.+)$/.match(address[:name]) 170: xml.tag! 'firstName', m[1] 171: xml.tag! 'lastName', m[2] 172: end 173: if m = /^\s*(\d+)\s+(.+)$/.match(address[:address1]) 174: xml.tag! 'street', m[2] 175: house_number = m[1] 176: else 177: xml.tag! 'street', address[:address1] 178: end 179: xml.tag! 'houseName', address[:address2] if address[:address2] 180: xml.tag! 'houseNumber', house_number if house_number.present? 181: xml.tag! 'postalCode', (address[:zip].present? ? address[:zip] : "0000") 182: xml.tag! 'city', address[:city] if address[:city] 183: xml.tag! 'state', (address[:state].present? ? address[:state] : 'N/A') 184: xml.tag! 'countryCode', address[:country] 185: xml.tag! 'telephoneNumber', address[:phone] if address[:phone] 186: end 187: end 188: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 135 135: def add_amount(xml, money, options) 136: xml.tag! 'amount', 137: :value => amount(money), 138: 'currencyCode' => (options[:currency] || currency(money)), 139: 'exponent' => 2 140: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 142 142: def add_payment_method(xml, amount, payment_method, options) 143: if payment_method.is_a?(String) 144: xml.tag! 'payAsOrder', 'orderCode' => payment_method do 145: add_amount(xml, amount, options) 146: end 147: else 148: xml.tag! 'paymentDetails' do 149: xml.tag! CARD_CODES[card_brand(payment_method)] do 150: xml.tag! 'cardNumber', payment_method.number 151: xml.tag! 'expiryDate' do 152: xml.tag! 'date', 'month' => format(payment_method.month, :two_digits), 'year' => format(payment_method.year, :four_digits) 153: end 154: 155: xml.tag! 'cardHolderName', payment_method.name 156: xml.tag! 'cvc', payment_method.verification_value 157: 158: add_address(xml, 'cardAddress', (options[:billing_address] || options[:address])) 159: end 160: end 161: end 162: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 111 111: def build_capture_request(money, authorization, options) 112: build_order_modify_request(authorization) do |xml| 113: xml.tag! 'capture' do 114: time = Time.now 115: xml.tag! 'date', 'dayOfMonth' => time.day, 'month' => time.month, 'year'=> time.year 116: add_amount(xml, money, options) 117: end 118: end 119: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 86 86: def build_order_inquiry_request(authorization, options) 87: build_request do |xml| 88: xml.tag! 'inquiry' do 89: xml.tag! 'orderInquiry', 'orderCode' => authorization 90: end 91: end 92: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 76 76: def build_order_modify_request(authorization) 77: build_request do |xml| 78: xml.tag! 'modify' do 79: xml.tag! 'orderModification', 'orderCode' => authorization do 80: yield xml 81: end 82: end 83: end 84: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 127 127: def build_refund_request(money, authorization, options) 128: build_order_modify_request(authorization) do |xml| 129: xml.tag! 'refund' do 130: add_amount(xml, money, options) 131: end 132: end 133: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 66 66: def build_request 67: xml = Builder::XmlMarkup.new :indent => 2 68: xml.instruct! 69: xml.declare! :DOCTYPE, :paymentService, :PUBLIC, "-//WorldPay//DTD WorldPay PaymentService v1//EN", "http://dtd.wp3.rbsworldpay.com/paymentService_v1.dtd" 70: xml.tag! 'paymentService', 'version' => "1.4", 'merchantCode' => @options[:login] do 71: yield xml 72: end 73: xml.target! 74: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 121 121: def build_void_request(authorization, options) 122: build_order_modify_request(authorization) do |xml| 123: xml.tag! 'cancel' 124: end 125: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 207 207: def commit(action, request) 208: xmr = ssl_post((test? ? TEST_URL : LIVE_URL), 209: request, 210: 'Content-Type' => 'text/xml', 211: 'Authorization' => encoded_credentials) 212: 213: raw = parse(action, xmr) 214: 215: Response.new( 216: success_from(raw), 217: message_from(raw), 218: raw, 219: :authorization => authorization_from(raw), 220: :test => test?) 221: 222: rescue ActiveMerchant::ResponseError => e 223: if e.response.code.to_s == "401" 224: return Response.new(false, "Invalid credentials", {}, :test => test?) 225: else 226: raise e 227: end 228: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 246 246: def encoded_credentials 247: credentials = "#{@options[:login]}:#{@options[:password]}" 248: "Basic #{[credentials].pack('m').strip}" 249: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 62 62: def inquire(authorization, options={}) 63: commit 'inquiry', build_order_inquiry_request(authorization, options) 64: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 235 235: def message_from(raw) 236: (raw[:iso8583_return_code_description] || 237: raw[:error] || 238: "SUCCESS") 239: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 190 190: def parse(action, xml) 191: parse_element({:action => action}, REXML::Document.new(xml)) 192: end
# File lib/active_merchant/billing/gateways/worldpay.rb, line 194 194: def parse_element(raw, node) 195: node.attributes.each do |k, v| 196: raw["#{node.name.underscore}_#{k.underscore}".to_sym] = v 197: end 198: if node.has_elements? 199: raw[node.name.underscore.to_sym] = true unless node.name.blank? 200: node.elements.each{|e| parse_element(raw, e) } 201: else 202: raw[node.name.underscore.to_sym] = node.text unless node.text.nil? 203: end 204: raw 205: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.