@@ -5,14 +5,16 @@ module Payments
55 class AdyenService < BaseService
66 include Lago ::Adyen ::ErrorHandlable
77 include Customers ::PaymentProviderFinder
8+ include TypedResults
89
910 PROVIDER_NAME = "Adyen"
1011
11- def initialize ( invoice = nil )
12- @invoice = invoice
12+ RESULTS = {
13+ update_payment_status : BaseResult [ :payment , :invoice ] ,
14+ generate_payment_url : BaseResult [ :payment_url ]
15+ } . freeze
1316
14- super
15- end
17+ private
1618
1719 def update_payment_status ( provider_payment_id :, status :, amount_cents : nil , metadata : { } )
1820 payment = if metadata [ :payment_type ] == "one-time"
@@ -43,7 +45,8 @@ def update_payment_status(provider_payment_id:, status:, amount_cents: nil, meta
4345 result . fail_with_error! ( e )
4446 end
4547
46- def generate_payment_url ( payment_intent )
48+ def generate_payment_url ( invoice , payment_intent )
49+ @invoice = invoice
4750 res = client . checkout . payment_links_api . payment_links (
4851 Lago ::Adyen ::Params . new ( payment_url_params ( payment_intent ) ) . to_h ,
4952 headers : { "Idempotency-Key" => payment_intent . id }
@@ -61,8 +64,6 @@ def generate_payment_url(payment_intent)
6164 result . third_party_failure! ( third_party : PROVIDER_NAME , error_code : e . code , error_message : e . msg )
6265 end
6366
64- private
65-
6667 attr_accessor :invoice
6768
6869 delegate :organization , :customer , to : :invoice
@@ -126,6 +127,8 @@ def payment_url_params(payment_intent)
126127 end
127128
128129 def update_invoice_payment_status ( payment_status :, deliver_webhook : true )
130+ @invoice = result . invoice
131+
129132 params = {
130133 payment_status :,
131134 ready_for_payment_processing : payment_status . to_sym != :succeeded
0 commit comments