Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 78 additions & 76 deletions lib/payment_services/adv_cash/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,96 +2,98 @@

require 'savon'

class PaymentServices::AdvCash
class Client
include AutoLogger
TIMEOUT = 10
SOAP_URL = 'https://account.volet.com/wsm/apiWebService?wsdl'
module PaymentServices
class AdvCash
class Client
include AutoLogger
TIMEOUT = 10
SOAP_URL = 'https://account.volet.com/wsm/apiWebService?wsdl'

def initialize(api_name:, authentication_token:, account_email:)
@api_name = api_name
@authentication_token = authentication_token
@account_email = account_email
end
def initialize(api_name:, authentication_token:, account_email:)
@api_name = api_name
@authentication_token = authentication_token
@account_email = account_email
end

def create_invoice(params:)
safely_parse soap_request(
url: SOAP_URL,
operation: :create_p2p_order,
body: {
arg0: authentication_params,
arg1: params
}
)
end
def create_invoice(params:)
safely_parse soap_request(
url: SOAP_URL,
operation: :create_p2p_order,
body: {
arg0: authentication_params,
arg1: params
}
)
end

def find_invoice(deposit_id:)
safely_parse soap_request(
url: SOAP_URL,
operation: :find_p2p_order_by_order_id,
body: {
arg0: authentication_params,
arg1: deposit_id
}
)
end
def find_invoice(deposit_id:)
safely_parse soap_request(
url: SOAP_URL,
operation: :find_p2p_order_by_order_id,
body: {
arg0: authentication_params,
arg1: deposit_id
}
)
end

def create_payout(params:)
safely_parse soap_request(
url: SOAP_URL,
operation: :send_money,
body: {
arg0: authentication_params,
arg1: params
}
)
end
def create_payout(params:)
safely_parse soap_request(
url: SOAP_URL,
operation: :send_money,
body: {
arg0: authentication_params,
arg1: params
}
)
end

def find_transaction(id:)
safely_parse soap_request(
url: SOAP_URL,
operation: :find_transaction,
body: {
arg0: authentication_params,
arg1: id
}
)
end
def find_transaction(id:)
safely_parse soap_request(
url: SOAP_URL,
operation: :find_transaction,
body: {
arg0: authentication_params,
arg1: id
}
)
end

private
private

attr_reader :api_name, :authentication_token, :account_email
attr_reader :api_name, :authentication_token, :account_email

def encrypted_token
sign_string = "#{authentication_token}:#{Time.now.utc.strftime('%Y%m%d:%H')}"
def encrypted_token
sign_string = "#{authentication_token}:#{Time.now.utc.strftime('%Y%m%d:%H')}"

Digest::SHA256.hexdigest(sign_string).upcase
end
Digest::SHA256.hexdigest(sign_string).upcase
end

def soap_request(url:, operation:, body:)
logger.info "Request operation: #{operation} to #{url} with payload #{body}"
def soap_request(url:, operation:, body:)
logger.info "Request operation: #{operation} to #{url} with payload #{body}"

Savon.client(wsdl: url, open_timeout: TIMEOUT, read_timeout: TIMEOUT).call(operation, message: body)
end
Savon.client(wsdl: url, open_timeout: TIMEOUT, read_timeout: TIMEOUT).call(operation, message: body)
end

def safely_parse(response)
res = response.body
logger.info "Response: #{res}"
res
rescue Savon::SOAPFault => err
logger.warn "Request failed #{response.class} #{response.body}"
Bugsnag.notify err do |report|
report.add_tab(:response, response_class: response.class, response_body: response.body)
def safely_parse(response)
res = response.body
logger.info "Response: #{res}"
res
rescue Savon::SOAPFault => err
logger.warn "Request failed #{response.class} #{response.body}"
Bugsnag.notify err do |report|
report.add_tab(:response, response_class: response.class, response_body: response.body)
end
response.body
end
response.body
end

def authentication_params
{
apiName: api_name,
authenticationToken: encrypted_token,
accountEmail: account_email
}
def authentication_params
{
apiName: api_name,
authenticationToken: encrypted_token,
accountEmail: account_email
}
end
end
end
end
32 changes: 17 additions & 15 deletions lib/payment_services/adv_cash/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@

# Copyright (c) 2018 FINFEX https://github.com/finfex

class PaymentServices::AdvCash
class Invoice < ::PaymentServices::Base::FiatInvoice
SUCCESS_PROVIDER_STATE = 'COMPLETED'
FAILED_PROVIDER_STATES = %w(EXPIRED CANCELED)
module PaymentServices
class AdvCash
class Invoice < ::PaymentServices::Base::FiatInvoice
SUCCESS_PROVIDER_STATE = 'COMPLETED'
FAILED_PROVIDER_STATES = %w(EXPIRED CANCELED)

self.table_name = 'adv_cash_invoices'
self.table_name = 'adv_cash_invoices'

monetize :amount_cents, as: :amount
monetize :amount_cents, as: :amount

def formatted_amount
format('%.2f', amount.to_f)
end
def formatted_amount
format('%.2f', amount.to_f)
end

private
private

def provider_succeed?
provider_state == SUCCESS_PROVIDER_STATE
end
def provider_succeed?
provider_state == SUCCESS_PROVIDER_STATE
end

def provider_failed?
provider_state.in? FAILED_PROVIDER_STATES
def provider_failed?
provider_state.in? FAILED_PROVIDER_STATES
end
end
end
end
88 changes: 45 additions & 43 deletions lib/payment_services/adv_cash/invoicer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,51 @@
require_relative 'invoice'
require_relative 'client'

class PaymentServices::AdvCash
class Invoicer < ::PaymentServices::Base::Invoicer
def create_invoice(money)
Invoice.create!(amount: money, order_public_id: order.public_id)
response = client.create_invoice(params: invoice_params).dig(:create_p2p_order_response, :return)

invoice.update!(
deposit_id: response[:order_id],
pay_url: response[:payment_url]
)
end

def pay_invoice_url
invoice.present? ? URI.parse(invoice.reload.pay_url) : ''
end

def async_invoice_state_updater?
true
end

def update_invoice_state!
transaction = client.find_invoice(deposit_id: invoice.deposit_id).dig(:find_p2p_order_by_order_id_response, :return)
invoice.update_state_by_provider(transaction[:status])
end

def invoice
@invoice ||= Invoice.find_by(order_public_id: order.public_id)
end

def invoice_params
currency = invoice.amount_currency.to_s
currency = 'RUR' if currency == 'RUB'
{
amount: invoice.formatted_amount,
currency: currency,
receiver: order.income_wallet.adv_cash_merchant_email,
orderId: order.public_id.to_s,
redirectUrl: order.success_redirect
}
end

def client
@client ||= Client.new(api_name: order.income_wallet.merchant_id, authentication_token: api_key, account_email: order.income_wallet.adv_cash_merchant_email)
module PaymentServices
class AdvCash
class Invoicer < ::PaymentServices::Base::Invoicer
def create_invoice(money)
Invoice.create!(amount: money, order_public_id: order.public_id)
response = client.create_invoice(params: invoice_params).dig(:create_p2p_order_response, :return)

invoice.update!(
deposit_id: response[:order_id],
pay_url: response[:payment_url]
)
end

def pay_invoice_url
invoice.present? ? URI.parse(invoice.reload.pay_url) : ''
end

def async_invoice_state_updater?
true
end

def update_invoice_state!
transaction = client.find_invoice(deposit_id: invoice.deposit_id).dig(:find_p2p_order_by_order_id_response, :return)
invoice.update_state_by_provider(transaction[:status])
end

def invoice
@invoice ||= Invoice.find_by(order_public_id: order.public_id)
end

def invoice_params
currency = invoice.amount_currency.to_s
currency = 'RUR' if currency == 'RUB'
{
amount: invoice.formatted_amount,
currency: currency,
receiver: order.income_wallet.adv_cash_merchant_email,
orderId: order.public_id.to_s,
redirectUrl: order.success_redirect
}
end

def client
@client ||= Client.new(api_name: order.income_wallet.merchant_id, authentication_token: api_key, account_email: order.income_wallet.adv_cash_merchant_email)
end
end
end
end
Loading