-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(payment-url): generate payment url for stripe and adyen (#1628)
* add logic for generating stripe one time payment * add specs * add logic for adyen * add adyen specs * feat(invoice-payment-url): Add setup for invoice payment url (#1635) * setup invoice payment url retrieval * fix specs * small update * add small fix * fix linter issues * feat(payment-url): handle incoming webhooks (#1644) * handle incoming webhooks * fix linter issues
- Loading branch information
1 parent
4c2e135
commit 6ff82e4
Showing
16 changed files
with
633 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
app/serializers/v1/payment_providers/invoice_payment_serializer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module V1 | ||
module PaymentProviders | ||
class InvoicePaymentSerializer < ModelSerializer | ||
def serialize | ||
{ | ||
lago_customer_id: model.customer&.id, | ||
external_customer_id: model.customer&.external_id, | ||
payment_provider: model.customer&.payment_provider, | ||
lago_invoice_id: model.id, | ||
payment_url: options[:payment_url], | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/services/invoices/payments/generate_payment_url_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
module Invoices | ||
module Payments | ||
class GeneratePaymentUrlService < BaseService | ||
def initialize(invoice:) | ||
@invoice = invoice | ||
@provider = invoice&.customer&.payment_provider&.to_s | ||
|
||
super | ||
end | ||
|
||
def call | ||
return result.not_found_failure!(resource: 'invoice') if invoice.blank? | ||
return result.single_validation_failure!(error_code: 'no_linked_payment_provider') unless provider | ||
return result.single_validation_failure!(error_code: 'invalid_payment_provider') if provider == 'gocardless' | ||
|
||
if invoice.succeeded? || invoice.voided? || invoice.draft? | ||
return result.single_validation_failure!(error_code: 'invalid_invoice_status_or_payment_status') | ||
end | ||
|
||
payment_url_result = Invoices::Payments::PaymentProviders::Factory.new_instance(invoice:).generate_payment_url | ||
|
||
return payment_url_result unless payment_url_result.success? | ||
|
||
if payment_url_result.payment_url.blank? | ||
return result.single_validation_failure!(error_code: 'payment_provider_error') | ||
end | ||
|
||
payment_url_result | ||
end | ||
|
||
private | ||
|
||
attr_reader :invoice, :provider | ||
end | ||
end | ||
end |
26 changes: 26 additions & 0 deletions
26
app/services/invoices/payments/payment_providers/factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Invoices | ||
module Payments | ||
module PaymentProviders | ||
class Factory | ||
def self.new_instance(invoice:) | ||
service_class(invoice.customer&.payment_provider).new(invoice) | ||
end | ||
|
||
def self.service_class(payment_provider) | ||
case payment_provider&.to_s | ||
when 'stripe' | ||
Invoices::Payments::StripeService | ||
when 'adyen' | ||
Invoices::Payments::AdyenService | ||
when 'gocardless' | ||
Invoices::Payments::GocardlessService | ||
else | ||
raise(NotImplementedError) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
spec/fixtures/adyen/webhook_authorisation_payment_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"live": "false", | ||
"notificationItems": [ | ||
{ | ||
"NotificationRequestItem": { | ||
"additionalData": { | ||
"authCode": "051793", | ||
"paymentLinkId": "PLF11278A8985273C2", | ||
"metadata.payment_type": "one-time", | ||
"cardSummary": "1142", | ||
"metadata.invoice_type": "subscription", | ||
"checkout.cardAddedBrand": "visa", | ||
"metadata.invoice_issuing_date": "2024-01-24", | ||
"expiryDate": "03/2030", | ||
"metadata.lago_customer_id": "a5488a6c-d2ed-44fd-8c97-7fcca4a6a84a", | ||
"threeds2.cardEnrolled": "false", | ||
"recurringProcessingModel": "CardOnFile", | ||
"metadata.lago_invoice_id": "ec82efeb-88bb-44f8-ba30-0d55b3fd583a" | ||
}, | ||
"amount": { | ||
"currency": "EUR", | ||
"value": 71 | ||
}, | ||
"eventCode": "AUTHORISATION", | ||
"eventDate": "2024-01-26T14:06:02+01:00", | ||
"merchantAccountCode": "LagoAccountECOM", | ||
"merchantReference": "HOO-3588-202401-033", | ||
"operations": [ | ||
"CANCEL", | ||
"CAPTURE", | ||
"REFUND" | ||
], | ||
"paymentMethod": "visa", | ||
"pspReference": "SGVWRSNQLDQ2WN82", | ||
"reason": "051793:1142:03/2030", | ||
"success": "true" | ||
} | ||
} | ||
] | ||
} |
Oops, something went wrong.