Class: Mpp::Methods::Stripe::StripeMethod

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

Overview

Stripe payment method implementation. Handles SPT-based payments through Stripe’s Business Network.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(secret_key:, network_id:, payment_methods: nil, metadata: nil, currency: Defaults::DEFAULT_CURRENCY, decimals: Defaults::DEFAULT_DECIMALS, external_id: nil) ⇒ StripeMethod

Returns a new instance of StripeMethod.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mpp/methods/stripe/stripe_method.rb', line 15

def initialize(secret_key:, network_id:, payment_methods: nil,
  metadata: nil, currency: Defaults::DEFAULT_CURRENCY,
  decimals: Defaults::DEFAULT_DECIMALS, external_id: nil)
  unless payment_methods.is_a?(Array) &&
      payment_methods.any? &&
      payment_methods.all? { |type| type.is_a?(String) && !type.strip.empty? }
    raise ArgumentError, "payment_methods must be a non-empty array of Stripe payment method type strings"
  end

  @name = "stripe"
  @secret_key = secret_key
  @network_id = network_id
  @payment_methods = payment_methods
  @metadata = 
  @external_id = external_id
  @currency = currency
  @recipient = network_id
  @decimals = decimals
  @intents = {}
end

Instance Attribute Details

#currencyObject (readonly)

Returns the value of attribute currency.



12
13
14
# File 'lib/mpp/methods/stripe/stripe_method.rb', line 12

def currency
  @currency
end

#decimalsObject (readonly)

Returns the value of attribute decimals.



12
13
14
# File 'lib/mpp/methods/stripe/stripe_method.rb', line 12

def decimals
  @decimals
end

#intentsObject

Returns the value of attribute intents.



13
14
15
# File 'lib/mpp/methods/stripe/stripe_method.rb', line 13

def intents
  @intents
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/mpp/methods/stripe/stripe_method.rb', line 12

def name
  @name
end

#recipientObject (readonly)

Returns the value of attribute recipient.



12
13
14
# File 'lib/mpp/methods/stripe/stripe_method.rb', line 12

def recipient
  @recipient
end

Instance Method Details

#transform_request(request, _credential) ⇒ Object

Transform request - injects Stripe-specific methodDetails.



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mpp/methods/stripe/stripe_method.rb', line 37

def transform_request(request, _credential)
  method_details = request.fetch("methodDetails", {})
  method_details = {} unless method_details.is_a?(Hash)

  method_details["networkId"] = @network_id
  method_details["paymentMethodTypes"] = @payment_methods
  method_details["metadata"] = @metadata if @metadata

  transformed = request.merge("methodDetails" => method_details)
  transformed["externalId"] = @external_id if !@external_id.nil? && !transformed.key?("externalId")
  transformed
end