Class: PaymentsApi::Requests::CreateCardPayment

Inherits:
Object
  • Object
show all
Includes:
Traits::ApiRequest
Defined in:
lib/payments_api/requests/create_card_payment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount:, reference:, description:, return_url:, **optional_details) ⇒ PaymentsApi::Requests::CreateCardPayment

Instantiate a new payment

Parameters:

  • amount (Integer)

    The amount in pence, for instance, 14500 for 145

  • reference (String)

    The reference you wish to associate with this payment

  • description (String)

    A human-readable description of the payment that the user will see on the payment pages and admin tool

  • return_url (String)

    This is a URL that your service hosts for the user to return to, after their payment journey on GOV.UK Pay ends

  • optional_details (Hash)

    a customizable set of options

Options Hash (**optional_details):

  • Additional (Hash)

    properties to be sent in the payload, for example email or metadata

Raises:

  • (ArgumentError)

    if any of the mandatory params above are missing

See Also:



30
31
32
33
34
35
36
37
# File 'lib/payments_api/requests/create_card_payment.rb', line 30

def initialize(amount:, reference:, description:, return_url:, **optional_details)
  @optional_details = optional_details

  @amount = amount
  @reference = reference
  @description = description
  @return_url = return_url
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



8
9
10
# File 'lib/payments_api/requests/create_card_payment.rb', line 8

def amount
  @amount
end

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'lib/payments_api/requests/create_card_payment.rb', line 8

def description
  @description
end

#optional_detailsObject (readonly)

Returns the value of attribute optional_details.



8
9
10
# File 'lib/payments_api/requests/create_card_payment.rb', line 8

def optional_details
  @optional_details
end

#referenceObject (readonly)

Returns the value of attribute reference.



8
9
10
# File 'lib/payments_api/requests/create_card_payment.rb', line 8

def reference
  @reference
end

#return_urlObject (readonly)

Returns the value of attribute return_url.



8
9
10
# File 'lib/payments_api/requests/create_card_payment.rb', line 8

def return_url
  @return_url
end

Instance Method Details

#callResponses::PaymentResult

Create a new payment



47
48
49
50
51
# File 'lib/payments_api/requests/create_card_payment.rb', line 47

def call
  Responses::PaymentResult.new(
    http_client.post(endpoint, payload)
  )
end

#endpointObject



53
54
55
# File 'lib/payments_api/requests/create_card_payment.rb', line 53

def endpoint
  '/v1/payments'
end

#payloadObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/payments_api/requests/create_card_payment.rb', line 57

def payload
  {
    amount: amount,
    reference: reference,
    description: description,
    return_url: return_url
  }.merge(
    optional_details
  )
end