Class: DPay::PaymentService

Inherits:
Object
  • Object
show all
Defined in:
lib/dpay/payment/payment_service.rb,
sig/dpay/payment/payment_service.rbs

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ PaymentService

Returns a new instance of PaymentService.

Parameters:



5
6
7
# File 'lib/dpay/payment/payment_service.rb', line 5

def initialize(api)
  @api = api
end

Instance Method Details

#details(transaction_id) ⇒ Transaction

Parameters:

  • transaction_id (String)

Returns:



22
23
24
25
26
27
# File 'lib/dpay/payment/payment_service.rb', line 22

def details(transaction_id)
  body = { "service" => @api.service, "transaction_id" => transaction_id }
  body["checksum"] = @api.checksum.ordered_body(body.values)

  Transaction.from_api(@api.post_json(Internal::BaseUrls::PANEL, "/api/v1/pbl/details", body))
end

#register(request) ⇒ RegisteredPayment

Parameters:

Returns:



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dpay/payment/payment_service.rb', line 9

def register(request)
  body = request.to_body(@api.service)
  body["checksum"] = @api.checksum.secret_second(
    @api.service,
    [body["value"], body["url_success"], body["url_fail"], body["url_ipn"]]
  )

  data = @api.post_json(Internal::BaseUrls::API_PAYMENTS, "/api/v1_0/payments/register", body)
  raise PaymentRejectedError.from_api(data) if rejected?(data)

  RegisteredPayment.from_api(data)
end

#rejected?(data) ⇒ Boolean

Parameters:

  • data (Hash[String, untyped])

Returns:

  • (Boolean)


31
32
33
# File 'lib/dpay/payment/payment_service.rb', line 31

def rejected?(data)
  data["error"] == true || data["status"] == false
end