Class: Omnipay::Adapters::Mangopay

Inherits:
Object
  • Object
show all
Defined in:
lib/omnipay/adapters/mangopay.rb,
lib/omnipay/adapters/mangopay/client.rb

Defined Under Namespace

Classes: Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callback_url, config = {}) ⇒ Mangopay

Returns a new instance of Mangopay.

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
# File 'lib/omnipay/adapters/mangopay.rb', line 19

def initialize(callback_url, config = {})

  raise ArgumentError.new("Missing client_id, client_passphrase, or wallet_id parameter") unless [config[:client_id], config[:client_passphrase], config[:wallet_id]].all?

  @client = Client.new(config[:client_id], config[:client_passphrase], :sandbox => !!config[:sandbox])
  @callback_url = callback_url
  @wallet_id = config[:wallet_id]

end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



17
18
19
# File 'lib/omnipay/adapters/mangopay.rb', line 17

def client
  @client
end

Instance Method Details

#callback_hash(params) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/omnipay/adapters/mangopay.rb', line 47

def callback_hash(params)

  transaction_id = params[:transactionId]

  begin
    response = @client.get "/payins/#{transaction_id}"
  rescue Mangopay::Client::Error => e
    return {
      :success => false,
      :error => Omnipay::INVALID_RESPONSE,
      :error_message => "Could not fetch details of transaction #{transaction_id}"
    }
  end

  # Check if the response is valid
  if response['code'] != 200
    return {
      :success => false,
      :error => Omnipay::INVALID_RESPONSE
    }
  end


  # Successful transaction
  if response['Status'] == 'SUCCEEDED'
    {
      :success => true,
      :amount => response['DebitedFunds']['Amount'],
      :transaction_id => transaction_id
    }
  else

    # Cancelation
    if ['101001', '101002'].include? response['ResultCode']
      {
        :success => false,
        :error => Omnipay::CANCELATION
      }
    else
      {
        :success => false,
        :error => Omnipay::PAYMENT_REFUSED,
        :error_message => "Refused payment for transaction #{transaction_id}.\nCode : #{response['ResultCode']}\nMessage : #{response['ResultMessage']}"
      }
    end
  end
end

#request_phase(amount, params = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/omnipay/adapters/mangopay.rb', line 30

def request_phase(amount, params = {})

  transaction_id, redirect_url = create_web_payin(amount, params)

  # Generate the path and query parameters from the returned redirect_url string
  uri = URI(redirect_url)

  return [
    'GET', 
    "#{uri.scheme}://#{uri.host}#{uri.path}", 
    Rack::Utils.parse_nested_query(uri.query), 
    transaction_id
  ]

end