Class: PayuPl::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/payu_pl/client.rb

Constant Summary collapse

DEFAULT_PRODUCTION_BASE_URL =
"https://secure.payu.com"
DEFAULT_SANDBOX_BASE_URL =
"https://secure.snd.payu.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id:, client_secret:, access_token: nil, base_url: nil, environment: :production, open_timeout: 10, read_timeout: 30) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/payu_pl/client.rb', line 13

def initialize(
  client_id:,
  client_secret:,
  access_token: nil,
  base_url: nil,
  environment: :production,
  open_timeout: 10,
  read_timeout: 30
)
  @client_id = client_id
  @client_secret = client_secret
  @access_token = access_token

  @base_url = base_url || default_base_url_for(environment)
  validate!

  @transport = Transport.new(
    base_url: @base_url,
    access_token_provider: -> { @access_token },
    open_timeout: open_timeout,
    read_timeout: read_timeout
  )
end

Instance Attribute Details

#access_token ⇒ Object

Returns the value of attribute access_token.



11
12
13
# File 'lib/payu_pl/client.rb', line 11

def access_token
  @access_token
end

#base_url ⇒ Object (readonly)

Returns the value of attribute base_url.



10
11
12
# File 'lib/payu_pl/client.rb', line 10

def base_url
  @base_url
end

#client_id ⇒ Object (readonly)

Returns the value of attribute client_id.



10
11
12
# File 'lib/payu_pl/client.rb', line 10

def client_id
  @client_id
end

#client_secret ⇒ Object (readonly)

Returns the value of attribute client_secret.



10
11
12
# File 'lib/payu_pl/client.rb', line 10

def client_secret
  @client_secret
end

#transport ⇒ Object (readonly)

Returns the value of attribute transport.



10
11
12
# File 'lib/payu_pl/client.rb', line 10

def transport
  @transport
end

Instance Method Details

#cancel_order(order_id) ⇒ Object



55
56
57
# File 'lib/payu_pl/client.rb', line 55

def cancel_order(order_id)
  Orders::Cancel.new(client: self).call(order_id)
end

#capture_order(order_id, amount: nil, currency_code: nil) ⇒ Object



51
52
53
# File 'lib/payu_pl/client.rb', line 51

def capture_order(order_id, amount: nil, currency_code: nil)
  Orders::Capture.new(client: self).call(order_id, amount: amount, currency_code: currency_code)
end

#create_order(order_create_request) ⇒ Object

Orders



43
44
45
# File 'lib/payu_pl/client.rb', line 43

def create_order(order_create_request)
  Orders::Create.new(client: self).call(order_create_request)
end

#create_payout(payout_request) ⇒ Object

Payouts



82
83
84
# File 'lib/payu_pl/client.rb', line 82

def create_payout(payout_request)
  Payouts::Create.new(client: self).call(payout_request)
end

#create_refund(order_id, description:, amount: nil, ext_refund_id: nil) ⇒ Object

Refunds



64
65
66
# File 'lib/payu_pl/client.rb', line 64

def create_refund(order_id, description:, amount: nil, ext_refund_id: nil)
  Refunds::Create.new(client: self).call(order_id, description: description, amount: amount, ext_refund_id: ext_refund_id)
end

#list_refunds(order_id) ⇒ Object



68
69
70
# File 'lib/payu_pl/client.rb', line 68

def list_refunds(order_id)
  Refunds::List.new(client: self).call(order_id)
end

#oauth_token(grant_type: "client_credentials") ⇒ Object

OAuth



38
39
40
# File 'lib/payu_pl/client.rb', line 38

def oauth_token(grant_type: "client_credentials")
  Authorize::OAuthToken.new(client: self).call(grant_type: grant_type)
end

#retrieve_order(order_id) ⇒ Object



47
48
49
# File 'lib/payu_pl/client.rb', line 47

def retrieve_order(order_id)
  Orders::Retrieve.new(client: self).call(order_id)
end

#retrieve_payout(payout_id) ⇒ Object



86
87
88
# File 'lib/payu_pl/client.rb', line 86

def retrieve_payout(payout_id)
  Payouts::Retrieve.new(client: self).call(payout_id)
end

#retrieve_refund(order_id, refund_id) ⇒ Object



72
73
74
# File 'lib/payu_pl/client.rb', line 72

def retrieve_refund(order_id, refund_id)
  Refunds::Retrieve.new(client: self).call(order_id, refund_id)
end

#retrieve_shop_data(shop_id) ⇒ Object

Shops



77
78
79
# File 'lib/payu_pl/client.rb', line 77

def retrieve_shop_data(shop_id)
  Shops::Retrieve.new(client: self).call(shop_id)
end

#retrieve_statement(report_id) ⇒ Object

Statements



91
92
93
# File 'lib/payu_pl/client.rb', line 91

def retrieve_statement(report_id)
  Statements::Retrieve.new(client: self).call(report_id)
end

#retrieve_transactions(order_id) ⇒ Object



59
60
61
# File 'lib/payu_pl/client.rb', line 59

def retrieve_transactions(order_id)
  Orders::Transactions.new(client: self).call(order_id)
end