Class: Mpp::Methods::Stripe::ClientMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/mpp/methods/stripe/client_method.rb

Overview

Client-side Stripe method for creating SPT-based credentials.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(create_spt:, payment_method: nil, external_id: nil) ⇒ ClientMethod

Returns a new instance of ClientMethod.



11
12
13
14
15
16
# File 'lib/mpp/methods/stripe/client_method.rb', line 11

def initialize(create_spt:, payment_method: nil, external_id: nil)
  @name = "stripe"
  @create_spt = create_spt
  @payment_method = payment_method
  @external_id = external_id
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/mpp/methods/stripe/client_method.rb', line 9

def name
  @name
end

Instance Method Details

#create_credential(challenge) ⇒ Object

Create a credential to satisfy the given challenge.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mpp/methods/stripe/client_method.rb', line 19

def create_credential(challenge)
  request = challenge.request
  method_details = request["methodDetails"]
  method_details = {} unless method_details.is_a?(Hash)

  spt_id = @create_spt.call(
    amount: request["amount"],
    currency: request["currency"],
    network_id: method_details["networkId"],
    payment_method: @payment_method
  )

  payload = {"spt" => spt_id}
  payload["externalId"] = @external_id if @external_id

  Mpp::Credential.new(
    challenge: challenge.to_echo,
    payload: payload
  )
end