lib/payoneer/client.rb in payoneer-client-0.3 vs lib/payoneer/client.rb in payoneer-client-0.4

- old
+ new

@@ -37,18 +37,59 @@ p9: payment_date.strftime('%m/%d/%Y %H:%M:%S'), Currency: currency ) end + # Includes additional items as needed to be Payoneer SAFE compliant + def expanded_payout(payee_id:, client_reference_id:, amount:, currency:, description:, payout_date: Time.now, seller_id:, seller_name:, seller_url:, seller_type: 'ECOMMERCE', orders_type: 'url', path:, credentials:) + params = { + payee_id: payee_id, + client_reference_id: client_reference_id, + amount: amount, + currency: currency, + description: description, + payout_date: payout_date.strftime('%Y-%m-%d'), + orders_report: { + merchant: { + id: seller_id, + store: { + name: seller_name, + url: seller_url, + type: seller_type + } + }, + orders: { + type: orders_type, + path: path, + credentials: credentials + } + } + } + + encoded_credentials = 'Basic ' + Base64.encode64("#{configuration.username}:#{configuration.api_password}").chomp + response = RestClient.post "#{configuration.json_base_uri}/payouts", params.to_json, content_type: 'application/json', accept: :json, Authorization: encoded_credentials + raise ResponseError.new(code: response.code, body: response.body) if response.code != 200 + + hash = JSON.parse(response.body) + hash['PaymentID'] = hash['payout_id'] # Keep consistent with the normal payout response body + + if hash.key?('Code') + Response.new(hash['Code'], hash['Description']) + else + hash = block_given? ? yield(hash) : hash + Response.new(Response::OK_STATUS_CODE, hash) + end + end + def payout_details(payee_id:, payment_id:) post('GetPaymentStatus', p4: payee_id, p5: payment_id) end private def post(method_name, params = {}) - response = RestClient.post(configuration.base_uri, { + response = RestClient.post(configuration.xml_base_uri, { mname: method_name, p1: configuration.username, p2: configuration.api_password, p3: configuration.partner_id }.merge(params)) @@ -59,15 +100,10 @@ hash = Hash.from_xml(response.body).values.first if hash.key?('Code') Response.new(hash['Code'], hash['Description']) else - hash = if block_given? - yield(hash) - else - hash - end - + hash = block_given? ? yield(hash) : hash Response.new(Response::OK_STATUS_CODE, hash) end end end end