Class: WebPay

Inherits:
Object
  • Object
show all
Defined in:
lib/webpay.rb,
lib/webpay/error.rb,
lib/webpay/data_types.rb

Defined Under Namespace

Modules: ErrorResponse Classes: Account, AccountResponse, ApiConnectionError, ApiError, ApiResource, BasicListRequest, CardRequest, CardResponse, Charge, ChargeFeeResponse, ChargeIdRequest, ChargeListRequest, ChargeRequestCreate, ChargeRequestRefund, ChargeRequestWithAmount, ChargeResponse, ChargeResponseList, CreatedRange, Customer, CustomerIdRequest, CustomerRequestCreate, CustomerRequestUpdate, CustomerResponse, CustomerResponseList, DeletedResponse, EmptyRequest, Entity, ErrorBody, ErrorData, Event, EventData, EventIdRequest, EventListRequest, EventResponse, EventResponseList, InvalidRequestError, InvalidResponseError, Recursion, RecursionIdRequest, RecursionListRequest, RecursionRequestCreate, RecursionRequestResume, RecursionResponse, RecursionResponseList, Shop, ShopIdRequest, ShopRequestAlterStatus, ShopRequestCreate, ShopRequestUpdate, ShopResponse, ShopResponseList, Token, TokenIdRequest, TokenRequestCreate, TokenResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_token, options = {}) ⇒ WebPay

Initialize client

Parameters:

  • options (Hash) (defaults to: {})

    options



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/webpay.rb', line 23

def initialize(auth_token, options = {})
  options = options.each_with_object({}) { |kv, obj| k,v = kv; obj[k.to_s] = v }

  connection_options = options['faraday_options'] || {}
  connection_options['headers'] = {

    "Content-Type" => "application/json",

    "Accept" => "application/json",

    "User-Agent" => "Apipa-webpay/3.2.3 ruby",

    "Accept-Language" => "en",
  }
  connection_options['url'] = options['api_base'] || 'https://api.webpay.jp/v1'
  @conn = Faraday.new(connection_options) do |builder|
    builder.request :url_encoded
    builder.adapter Faraday.default_adapter
  end


  @conn.authorization(:Bearer, auth_token)

  @charge = WebPay::Charge.new(self)
  @customer = WebPay::Customer.new(self)
  @token = WebPay::Token.new(self)
  @event = WebPay::Event.new(self)
  @shop = WebPay::Shop.new(self)
  @recursion = WebPay::Recursion.new(self)
  @account = WebPay::Account.new(self)
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



18
19
20
# File 'lib/webpay.rb', line 18

def 
  @account
end

#chargeObject

Returns the value of attribute charge.



12
13
14
# File 'lib/webpay.rb', line 12

def charge
  @charge
end

#connObject (readonly)

Returns the value of attribute conn.



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

def conn
  @conn
end

#customerObject

Returns the value of attribute customer.



13
14
15
# File 'lib/webpay.rb', line 13

def customer
  @customer
end

#eventObject

Returns the value of attribute event.



15
16
17
# File 'lib/webpay.rb', line 15

def event
  @event
end

#recursionObject

Returns the value of attribute recursion.



17
18
19
# File 'lib/webpay.rb', line 17

def recursion
  @recursion
end

#shopObject

Returns the value of attribute shop.



16
17
18
# File 'lib/webpay.rb', line 16

def shop
  @shop
end

#tokenObject

Returns the value of attribute token.



14
15
16
# File 'lib/webpay.rb', line 14

def token
  @token
end

Instance Method Details

#_request(method, path, param_data) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/webpay.rb', line 71

def _request(method, path ,param_data)
  begin
    response = @conn.__send__(method) do |req|
      req.url(path)
      req.params = param_data.query_params
      req.body = JSON.dump(param_data.request_body)
    end
  rescue Faraday::Error::ClientError, URI::InvalidURIError => e
    raise WebPay::ApiConnectionError.in_request(e)
  end
  handle_response(response)
end

#receive_webhook(request_body) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/webpay.rb', line 61

def receive_webhook(request_body)
  json_data =
    begin
      JSON_CLASS.load(request_body)
    rescue JSON_CLASS::ParserError => e
      raise WebPay::ApiConnectionError.new('Webhook request body is invalid JSON string', e)
    end
  WebPay::EventResponse.new(json_data)
end

#set_accept_language(value) ⇒ Object



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

def set_accept_language(value)
  @conn.headers['Accept-Language'] = value
end