Class: ParkingTicket::Clients::PayByPhone::Client

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/clients/pay_by_phone/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ Client

Returns a new instance of Client.



185
186
187
188
# File 'lib/clients/pay_by_phone/client.rb', line 185

def initialize(username, password)
  @username = username
  @password = password
end

Class Method Details

.account_id(token) ⇒ Object



50
51
52
# File 'lib/clients/pay_by_phone/client.rb', line 50

def (token)
  connection(token).get('/parking/accounts').body.dig(0, 'id')
end

.auth(username, password) ⇒ Object



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

def auth(username, password)
  conn = Faraday.new('https://auth.paybyphoneapis.com') do |f|
    f.response :json
    f.response :raise_error
  end

  conn.post(
    '/token',
    URI.encode_www_form({
                          grant_type: 'password',
                          username: username,
                          password: password,
                          client_id: 'paybyphone_web'
                        }),
    {
      'Accept' => 'application/json, text/plain, */*',
      'X-Pbp-ClientType' => 'WebApp'
    }
  )
end

.new_ticket(token, account_id, license_plate:, zipcode:, rate_option_client_internal_id:, quantity:, time_unit:, quote_client_internal_id:, starts_on:, payment_method_id:) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/clients/pay_by_phone/client.rb', line 99

def new_ticket(token, , license_plate:, zipcode:, rate_option_client_internal_id:, quantity:,
               time_unit:, quote_client_internal_id:, starts_on:, payment_method_id:)
  base_data = {
    expireTime: nil,
    duration: {
      quantity: quantity.to_s,
      timeUnit: time_unit
    },
    licensePlate: license_plate,
    locationId: zipcode,
    rateOptionId: rate_option_client_internal_id,
    startTime: starts_on.to_s,
    quoteId: quote_client_internal_id,
    parkingAccountId: 
  }

  payment_data = {
    paymentMethod: {
      paymentMethodType: 'PaymentAccount',
      payload: {
        paymentAccountId: payment_method_id,
        clientBrowserDetails: {
          browserAcceptHeader: 'text/html',
          browserColorDepth: '30',
          browserJavaEnabled: 'false',
          browserLanguage: 'fr-FR',
          browserScreenHeight: '900',
          browserScreenWidth: '1440',
          browserTimeZone: '-60',
          browserUserAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36'
        }
      }
    }
  }

  final_data = payment_method_id ? base_data.merge(payment_data) : base_data

  connection(token).post(
    "/parking/accounts/#{}/sessions/",
    JSON.generate(final_data)
  ).body
end

.payment_methods(token) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/clients/pay_by_phone/client.rb', line 143

def payment_methods(token)
  connection = Faraday.new(
    url: 'https://payments.paybyphoneapis.com',
    headers: {
      accept: 'application/json, text/plain, */*',
      'accept-language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7',
      authorization: "Bearer #{token}",
      'content-type': 'application/json',
      'sec-fetch-dest': 'empty',
      'sec-fetch-mode': 'cors',
      'sec-fetch-site': 'cross-site',
      'x-api-key': 'zZ4ePLvoBBD1YwBGCo6P5DiPLDjSss3j',
      'x-pbp-clienttype': 'WebApp',
      Referer: 'https://m2.paybyphone.fr/',
      'Referrer-Policy': 'strict-origin-when-cross-origin'
    }
  ) do |f|
    f.response :json
    f.response :raise_error
  end

  connection.get('/v1/accounts').body
end

.quote(token, account_id, rate_option_id, zipcode, license_plate, quantity, time_unit) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/clients/pay_by_phone/client.rb', line 70

def quote(token, , rate_option_id, zipcode, license_plate, quantity, time_unit)
  connection(token).get(
    "/parking/accounts/#{}/quote",
    {
      locationId: zipcode,
      licensePlate: license_plate,
      rateOptionId: rate_option_id,
      durationTimeUnit: time_unit,
      durationQuantity: quantity,
      isParkUntil: false,
      parkingAccountId: 
    }
  ).body
end

.rate_options(token, account_id, zipcode, license_plate) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/clients/pay_by_phone/client.rb', line 36

def rate_options(token, , zipcode, license_plate)
  connection(token).get("/parking/locations/#{zipcode}/rateOptions",
                        {
                          parkingAccountId: ,
                          licensePlate: license_plate
                        }).body
end

.running_tickets(token, account_id) ⇒ Object



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

def running_tickets(token, )
  connection(token).get("/parking/accounts/#{}/sessions?periodType=Current").body
end

.vehicles(token) ⇒ Object



45
46
47
# File 'lib/clients/pay_by_phone/client.rb', line 45

def vehicles(token)
  connection(token).get('/identity/profileservice/v1/members/vehicles/paybyphone').body
end

Instance Method Details

#new_ticket(license_plate:, zipcode:, rate_option_client_internal_id:, quantity:, time_unit:, quote_client_internal_id:, starts_on:, payment_method_id:) ⇒ Object



231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/clients/pay_by_phone/client.rb', line 231

def new_ticket(license_plate:, zipcode:, rate_option_client_internal_id:, quantity:, time_unit:,
               quote_client_internal_id:, starts_on:, payment_method_id:)
  self.class.new_ticket(token, ,
                        license_plate: license_plate,
                        zipcode: zipcode,
                        rate_option_client_internal_id: rate_option_client_internal_id,
                        quantity: quantity,
                        time_unit: time_unit,
                        quote_client_internal_id: quote_client_internal_id,
                        starts_on: starts_on,
                        payment_method_id: payment_method_id)
end

#payment_methodsObject



206
207
208
# File 'lib/clients/pay_by_phone/client.rb', line 206

def payment_methods
  self.class.payment_methods(token)
end

#quote(rate_option_id, zipcode, license_plate, quantity, time_unit) ⇒ Object



214
215
216
# File 'lib/clients/pay_by_phone/client.rb', line 214

def quote(rate_option_id, zipcode, license_plate, quantity, time_unit)
  self.class.quote(token, , rate_option_id, zipcode, license_plate, quantity, time_unit)
end

#rate_options(zipcode, license_plate) ⇒ Object



196
197
198
# File 'lib/clients/pay_by_phone/client.rb', line 196

def rate_options(zipcode, license_plate)
  self.class.rate_options(token, , zipcode, license_plate)
end

#running_ticketsObject



201
202
203
# File 'lib/clients/pay_by_phone/client.rb', line 201

def running_tickets
  self.class.running_tickets(token, )
end

#vehiclesObject



191
192
193
# File 'lib/clients/pay_by_phone/client.rb', line 191

def vehicles
  self.class.vehicles(token)
end