Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(boleto): Introduce Boleto as a valid Stripe Payment Method #3111

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/payment_provider_customers/stripe_customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module PaymentProviderCustomers
class StripeCustomer < BaseCustomer
PAYMENT_METHODS = %w[card sepa_debit us_bank_account bacs_debit link].freeze
PAYMENT_METHODS = %w[card sepa_debit us_bank_account bacs_debit link boleto].freeze

validates :provider_payment_methods, presence: true
validate :allowed_provider_payment_methods
Expand Down
1 change: 1 addition & 0 deletions schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spec/graphql/types/customers/customer_type_enum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'rails_helper'

RSpec.describe Types::Customers::CustomerTypeEnum do
it 'enumerizes the correct values' do
it 'enumerates the correct values' do
expect(described_class.values.keys).to match_array(%w[company individual])
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Types::PaymentProviderCustomers::ProviderPaymentMethodsEnum do
it 'enumerates the correct values' do
expect(described_class.values.keys).to match_array(%w[card sepa_debit us_bank_account bacs_debit link boleto])
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@
File.read(Rails.root.join("spec/fixtures/stripe/customer_retrieve_response.json"))
end

let(:stripe_payment_intent) do
Stripe::PaymentIntent.construct_from(
id: "ch_123456",
let(:stripe_payment_intent_data) do
{
id: "pi_123456",
status: payment_status,
amount: invoice.total_amount_cents,
currency: invoice.currency
)
}
end

let(:payment_status) { "succeeded" }
Expand All @@ -71,8 +71,10 @@
stripe_payment_provider
stripe_customer

allow(Stripe::PaymentIntent).to receive(:create)
.and_return(stripe_payment_intent)
allow(Stripe::PaymentIntent).to receive(:create).and_call_original
stub_request(:post, "https://api.stripe.com/v1/payment_intents")
.to_return(body: stripe_payment_intent_data.to_json)

allow(SegmentTrackJob).to receive(:perform_later)
allow(Invoices::PrepaidCreditJob).to receive(:perform_later)

Expand Down Expand Up @@ -206,6 +208,9 @@

expect(result.error_message).to eq("error")
expect(result.error_code).to be_nil

expect(result.payment.status).to eq("failed")
expect(result.payment.payable_payment_status).to eq("failed")
end
end

Expand Down Expand Up @@ -247,6 +252,53 @@
end
end

context 'when invoice amount is too big to pay with Boleto' do
let(:organization) { create(:organization) }
let(:customer) { create(:customer, organization:) }
let(:subscription) { create(:subscription, organization:, customer:) }

let(:invoice) do
create(
:invoice,
organization:,
customer:,
total_amount_cents: 100_000_00,
currency: "BRL",
ready_for_payment_processing: true
)
end

before do
subscription

WebMock.stub_request(:post, "https://api.stripe.com/v1/payment_intents")
.to_return(status: 400, body: {
error: {
code: "amount_too_large",
doc_url: "https://stripe.com/docs/error-codes/amount-too-large",
message: "Amount must be no more than R$ 49,999.99 brl",
param: "amount",
request_log_url: "https://dashboard.stripe.com/test/logs/req_WAmkqXs7ajMNAU?t=1738144303",
type: "invalid_request_error"
}
}.to_json)
end

it "returns an empty result" do
result = create_service.call

expect(result).not_to be_success
expect(result.error).to be_a(BaseService::ServiceFailure)
expect(result.error.code).to eq("stripe_error")
expect(result.error.error_message).to eq("Amount must be no more than R$ 49,999.99 brl")

expect(result.error_message).to eq("Amount must be no more than R$ 49,999.99 brl")
expect(result.error_code).to eq("amount_too_large")
expect(result.payment.status).to eq("failed")
expect(result.payment.payable_payment_status).to eq("failed")
end
end

context "when payment status is processing" do
let(:payment_status) { "processing" }

Expand All @@ -271,16 +323,16 @@
context "when customers country is IN" do
let(:payment_status) { "requires_action" }

let(:stripe_payment_intent) do
Stripe::PaymentIntent.construct_from(
id: "ch_123456",
let(:stripe_payment_intent_data) do
{
id: "pi_123456",
status: payment_status,
amount: invoice.total_amount_cents,
currency: invoice.currency,
next_action: {
redirect_to_url: {url: "https://foo.bar"}
}
)
}
end

before do
Expand Down