Donations create StripeCharge events
This commit is contained in:
parent
ad4ef1db9c
commit
1b20e6499a
15 changed files with 870 additions and 6 deletions
77
app/models/stripe_charge.rb
Normal file
77
app/models/stripe_charge.rb
Normal file
|
@ -0,0 +1,77 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
||||
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
||||
class StripeCharge < ApplicationRecord
|
||||
include Model::SubtransactionPaymentable
|
||||
belongs_to :payment
|
||||
|
||||
delegate :gross_amount, :net_amount, :fee_total, to: :payment
|
||||
|
||||
delegate :currency, to: :nonprofit
|
||||
|
||||
concerning :JBuilder do # rubocop:disable Metrics/BlockLength
|
||||
included do
|
||||
setup_houid :stripechrg
|
||||
end
|
||||
|
||||
def to_builder(*expand) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
||||
init_builder(*expand) do |json|
|
||||
json.object 'stripe_transaction_charge'
|
||||
json.gross_amount do
|
||||
json.cents gross_amount
|
||||
json.currency currency
|
||||
end
|
||||
|
||||
json.net_amount do
|
||||
json.cents net_amount
|
||||
json.currency currency
|
||||
end
|
||||
|
||||
json.fee_total do
|
||||
json.cents fee_total
|
||||
json.currency currency
|
||||
end
|
||||
|
||||
json.created payment.date.to_i
|
||||
|
||||
json.stripe_id payment.charge.stripe_charge_id
|
||||
|
||||
json.type 'payment'
|
||||
|
||||
json.add_builder_expansion :nonprofit, :supporter, :subtransaction
|
||||
|
||||
json.add_builder_expansion :trx, json_attribute: :transaction
|
||||
end
|
||||
end
|
||||
|
||||
def to_id
|
||||
::Jbuilder.new do |json|
|
||||
json.(self, :id)
|
||||
json.object 'stripe_transaction_charge'
|
||||
json.type 'payment'
|
||||
end
|
||||
end
|
||||
|
||||
def publish_created # rubocop:disable Metrics/MethodLength
|
||||
Houdini.event_publisher.announce(
|
||||
:stripe_transaction_charge_created,
|
||||
to_event('stripe_transaction_charge.created',
|
||||
:nonprofit,
|
||||
:trx,
|
||||
:supporter,
|
||||
:subtransaction).attributes!
|
||||
)
|
||||
Houdini.event_publisher.announce(
|
||||
:payment_created,
|
||||
to_event(
|
||||
'payment.created',
|
||||
:nonprofit,
|
||||
:trx,
|
||||
:supporter,
|
||||
:subtransaction
|
||||
).attributes!
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
66
app/models/stripe_transaction.rb
Normal file
66
app/models/stripe_transaction.rb
Normal file
|
@ -0,0 +1,66 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
||||
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
||||
class StripeTransaction < ApplicationRecord
|
||||
include Model::Subtransactable
|
||||
delegate :created, to: :subtransaction
|
||||
|
||||
def net_amount
|
||||
subtransaction_payments.sum(&:net_amount)
|
||||
end
|
||||
|
||||
concerning :JBuilder do # rubocop:disable Metrics/BlockLength
|
||||
included do
|
||||
setup_houid :stripetrx
|
||||
end
|
||||
def to_builder(*expand) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
||||
init_builder(*expand) do |json|
|
||||
json.type 'subtransaction'
|
||||
json.created created.to_i
|
||||
json.initial_amount do
|
||||
json.cents amount || 0
|
||||
json.currency nonprofit.currency
|
||||
end
|
||||
|
||||
json.net_amount do
|
||||
json.cents net_amount
|
||||
json.currency nonprofit.currency
|
||||
end
|
||||
|
||||
if expand.include? :payments
|
||||
json.payments subtransaction_payments do |py|
|
||||
json.merge! py.to_builder.attributes!
|
||||
end
|
||||
else
|
||||
json.payments subtransaction_payments do |py|
|
||||
json.merge! py.to_id.attributes!
|
||||
end
|
||||
end
|
||||
|
||||
json.add_builder_expansion :nonprofit, :supporter
|
||||
|
||||
json.add_builder_expansion(
|
||||
:trx,
|
||||
json_attribute: :transaction
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def to_id
|
||||
::Jbuilder.new do |json|
|
||||
json.(self, :id)
|
||||
json.object 'stripe_transaction'
|
||||
json.type 'subtransaction'
|
||||
end
|
||||
end
|
||||
|
||||
def publish_created
|
||||
Houdini.event_publisher.announce(
|
||||
:stripe_transaction_created,
|
||||
to_event('stripe_transaction.created', :nonprofit, :trx, :supporter,
|
||||
:payments).attributes!
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -18,7 +18,7 @@ class Subtransaction < ApplicationRecord
|
|||
|
||||
has_many :subtransaction_payments # rubocop:disable Rails/HasManyOrHasOneDependent
|
||||
|
||||
delegated_type :subtransactable, types: %w[OfflineTransaction]
|
||||
delegated_type :subtransactable, types: %w[OfflineTransaction StripeTransaction]
|
||||
|
||||
scope :with_subtransactables, -> { includes(:subtransactable) }
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ class SubtransactionPayment < ApplicationRecord
|
|||
has_one :supporter, through: :subtransaction
|
||||
has_one :nonprofit, through: :subtransaction
|
||||
|
||||
delegated_type :paymentable, types: ['OfflineTransactionCharge']
|
||||
delegated_type :paymentable, types: %w[OfflineTransactionCharge StripeCharge]
|
||||
|
||||
delegate :gross_amount, :fee_total, :net_amount, to: :paymentable
|
||||
|
||||
|
|
9
db/migrate/20210506172332_create_stripe_transactions.rb
Normal file
9
db/migrate/20210506172332_create_stripe_transactions.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
class CreateStripeTransactions < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :stripe_transactions, id: :string do |t|
|
||||
t.integer :amount, null:false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
9
db/migrate/20210506202607_create_stripe_charges.rb
Normal file
9
db/migrate/20210506202607_create_stripe_charges.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
class CreateStripeCharges < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :stripe_charges, id: :string do |t|
|
||||
t.references :payment, foreign_key: true, id: :string
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
16
db/schema.rb
16
db/schema.rb
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2021_03_29_213633) do
|
||||
ActiveRecord::Schema.define(version: 2021_05_06_202607) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_stat_statements"
|
||||
|
@ -782,6 +782,19 @@ ActiveRecord::Schema.define(version: 2021_03_29_213633) do
|
|||
t.index ["tokenizable_id", "tokenizable_type"], name: "index_source_tokens_on_tokenizable_id_and_tokenizable_type"
|
||||
end
|
||||
|
||||
create_table "stripe_charges", id: :string, force: :cascade do |t|
|
||||
t.bigint "payment_id"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.index ["payment_id"], name: "index_stripe_charges_on_payment_id"
|
||||
end
|
||||
|
||||
create_table "stripe_transactions", id: :string, force: :cascade do |t|
|
||||
t.integer "amount", null: false
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
end
|
||||
|
||||
create_table "subtransaction_payments", id: :string, force: :cascade do |t|
|
||||
t.string "subtransaction_id"
|
||||
t.string "paymentable_type"
|
||||
|
@ -1008,6 +1021,7 @@ ActiveRecord::Schema.define(version: 2021_03_29_213633) do
|
|||
add_foreign_key "modern_campaign_gifts", "campaign_gifts"
|
||||
add_foreign_key "object_event_hook_configs", "nonprofits"
|
||||
add_foreign_key "offline_transaction_charges", "payments"
|
||||
add_foreign_key "stripe_charges", "payments"
|
||||
add_foreign_key "subtransaction_payments", "subtransactions"
|
||||
add_foreign_key "subtransactions", "transactions"
|
||||
add_foreign_key "ticket_purchases", "event_discounts"
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
// License: LGPL-3.0-or-later
|
||||
import type { HoudiniEvent } from "../../../common";
|
||||
import type { CommonStripeTransactionPayment } from ".";
|
||||
import type { PaymentAsId } from "..";
|
||||
|
||||
export interface ChargeAsId extends PaymentAsId {
|
||||
object: 'stripe_transaction_charge';
|
||||
}
|
||||
|
||||
export type Charge = CommonStripeTransactionPayment & ChargeAsId;
|
||||
|
||||
export type ChargeCreated = HoudiniEvent<'stripe_transaction_charge.created', Charge>;
|
||||
export type ChargeUpdated = HoudiniEvent<'stripe_transaction_charge.updated', Charge>;
|
||||
export type ChargeDeleted = HoudiniEvent<'stripe_transaction_charge.deleted', Charge>;
|
|
@ -1,6 +1,20 @@
|
|||
// License: LGPL-3.0-or-later
|
||||
import type { Subtransaction} from "..";
|
||||
import type { HouID, HoudiniEvent } from "../../../common";
|
||||
import type { Payment, Subtransaction} from "..";
|
||||
|
||||
export interface CommonStripeTransactionPayment extends Payment {
|
||||
stripe_id: string;
|
||||
subtransaction: HouID | StripeTransaction;
|
||||
}
|
||||
|
||||
export default interface StripeTransaction extends Subtransaction {
|
||||
object: 'stripe_transaction';
|
||||
}
|
||||
|
||||
export type StripeTransactionCreated = HoudiniEvent<'stripe_transaction.created', StripeTransaction>;
|
||||
export type StripeTransactionUpdated = HoudiniEvent<'stripe_transaction.updated', StripeTransaction>;
|
||||
export type StripeTransactionRefunded = HoudiniEvent<'stripe_transaction.refunded', StripeTransaction>;
|
||||
export type StripeTransactionDisputed = HoudiniEvent<'stripe_transaction.disputed', StripeTransaction>;
|
||||
export type StripeTransactionDeleted = HoudiniEvent<'stripe_transaction.deleted', StripeTransaction>;
|
||||
|
||||
export * from './Charge';
|
|
@ -44,10 +44,20 @@ module InsertDonation
|
|||
result['donation'] = insert_donation(data, entities)
|
||||
trx = entities[:supporter_id].transactions.build(amount: data['amount'])
|
||||
update_donation_keys(result)
|
||||
|
||||
don = trx.donations.build(amount: result['donation'].amount, legacy_donation: result['donation'])
|
||||
stripe_t = trx.build_subtransaction(
|
||||
subtransactable: StripeTransaction.new(amount: data['amount']),
|
||||
subtransaction_payments:[
|
||||
SubtransactionPayment.new(
|
||||
paymentable: StripeCharge.new(payment: Payment.find(result['payment']['id'])))
|
||||
],
|
||||
created: data['date']
|
||||
);
|
||||
trx.save!
|
||||
don.save!
|
||||
stripe_t.save!
|
||||
stripe_t.subtransaction_payments.each{|stp| stp.publish_created}
|
||||
stripe_t.publish_created
|
||||
don.publish_created
|
||||
trx.publish_created
|
||||
result['activity'] = InsertActivities.for_one_time_donations([result['payment'].id])
|
||||
|
|
9
spec/factories/stripe_charges.rb
Normal file
9
spec/factories/stripe_charges.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
||||
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
||||
FactoryBot.define do
|
||||
factory :stripe_charge do
|
||||
references { '' }
|
||||
end
|
||||
end
|
10
spec/factories/stripe_transactions.rb
Normal file
10
spec/factories/stripe_transactions.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
||||
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
||||
FactoryBot.define do
|
||||
factory :stripe_transaction do
|
||||
initial_amount { 1 }
|
||||
net_amount { 1 }
|
||||
end
|
||||
end
|
|
@ -199,6 +199,620 @@ describe InsertDonation do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'object event firing' do
|
||||
# all the same for all the types of donations; see #603
|
||||
let(:created_time) { Time.current }
|
||||
let(:common_builder) do
|
||||
{ 'supporter' => supporter.id,
|
||||
'nonprofit' => nonprofit.id }
|
||||
end
|
||||
|
||||
let(:common_builder_expanded) do
|
||||
{
|
||||
'supporter' => supporter_builder_expanded,
|
||||
'nonprofit' => np_builder_expanded
|
||||
}
|
||||
end
|
||||
|
||||
let(:common_builder_with_trx_id) do
|
||||
common_builder.merge(
|
||||
{
|
||||
'transaction' => match_houid('trx')
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
let(:common_builder_with_trx) do
|
||||
common_builder.merge(
|
||||
{
|
||||
'transaction' => transaction_builder
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
let(:np_builder_expanded) do
|
||||
{
|
||||
'id' => nonprofit.id,
|
||||
'name' => nonprofit.name,
|
||||
'object' => 'nonprofit'
|
||||
}
|
||||
end
|
||||
|
||||
let(:supporter_builder_expanded) do
|
||||
supporter_to_builder_base.merge({ 'name' => 'Fake Supporter Name' })
|
||||
end
|
||||
|
||||
let(:transaction_builder) do
|
||||
common_builder.merge(
|
||||
{
|
||||
'id' => match_houid('trx'),
|
||||
'object' => 'transaction',
|
||||
'amount' => {
|
||||
'cents' => charge_amount,
|
||||
'currency' => 'usd'
|
||||
},
|
||||
'created' => created_time.to_i,
|
||||
'subtransaction' => stripe_transaction_id_only,
|
||||
'subtransaction_payments' => [stripe_transaction_charge_id_only],
|
||||
'transaction_assignments' => [donation_id_only]
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
let(:transaction_builder_expanded) do
|
||||
transaction_builder.merge(
|
||||
common_builder_expanded,
|
||||
{
|
||||
'subtransaction' => stripe_transaction_builder,
|
||||
'subtransaction_payments' => [stripe_transaction_charge_builder],
|
||||
'transaction_assignments' => [donation_builder]
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
let(:stripe_transaction_id_only) do
|
||||
{
|
||||
'id' => match_houid('stripetrx'),
|
||||
'object' => 'stripe_transaction',
|
||||
'type' => 'subtransaction'
|
||||
}
|
||||
end
|
||||
|
||||
let(:stripe_transaction_builder) do
|
||||
stripe_transaction_id_only.merge(
|
||||
common_builder_with_trx_id,
|
||||
{
|
||||
'initial_amount' => {
|
||||
'cents' => charge_amount,
|
||||
'currency' => 'usd'
|
||||
},
|
||||
|
||||
'net_amount' => {
|
||||
'cents' => 67,
|
||||
'currency' => 'usd'
|
||||
},
|
||||
|
||||
'payments' => [stripe_transaction_charge_id_only],
|
||||
'created' => created_time.to_i
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
let(:stripe_transaction_builder_expanded) do
|
||||
stripe_transaction_builder.merge(
|
||||
common_builder_with_trx,
|
||||
common_builder_expanded,
|
||||
{
|
||||
'payments' => [stripe_transaction_charge_builder]
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
let(:stripe_transaction_charge_id_only) do
|
||||
{
|
||||
'id' => match_houid('stripechrg'),
|
||||
'object' => 'stripe_transaction_charge',
|
||||
'type' => 'payment'
|
||||
}
|
||||
end
|
||||
|
||||
let(:stripe_transaction_charge_builder) do
|
||||
stripe_transaction_charge_id_only.merge(
|
||||
common_builder_with_trx_id,
|
||||
{
|
||||
'gross_amount' => {
|
||||
'cents' => charge_amount,
|
||||
'currency' => 'usd'
|
||||
},
|
||||
'net_amount' => {
|
||||
'cents' => 67,
|
||||
'currency' => 'usd'
|
||||
},
|
||||
'fee_total' => {
|
||||
'cents' => -33,
|
||||
'currency' => 'usd'
|
||||
},
|
||||
'subtransaction' => stripe_transaction_id_only,
|
||||
'stripe_id' => /test_ch_\d+/,
|
||||
'created' => created_time.to_i
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
let(:stripe_transaction_charge_builder_expanded) do
|
||||
stripe_transaction_charge_builder.merge(
|
||||
common_builder_with_trx,
|
||||
common_builder_expanded,
|
||||
{
|
||||
'subtransaction' => stripe_transaction_builder
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
let(:donation_id_only) do
|
||||
{
|
||||
'id' => match_houid('don'),
|
||||
'object' => 'donation',
|
||||
'type' => 'trx_assignment'
|
||||
}
|
||||
end
|
||||
|
||||
let(:donation_builder) do
|
||||
donation_id_only.merge(common_builder_with_trx_id, {
|
||||
'amount' => {
|
||||
'cents' => charge_amount,
|
||||
'currency' => 'usd'
|
||||
},
|
||||
'designation' => 'designation',
|
||||
'dedication' => {
|
||||
'name' => 'a name',
|
||||
'type' => 'honor'
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
let(:donation_builder_expanded) do
|
||||
donation_builder.merge(common_builder_with_trx, common_builder_expanded)
|
||||
end
|
||||
|
||||
describe 'events donations' do
|
||||
describe 'general with_stripe create' do
|
||||
subject do
|
||||
process_event_donation do
|
||||
described_class.with_stripe(
|
||||
{
|
||||
amount: charge_amount,
|
||||
nonprofit_id: nonprofit.id,
|
||||
supporter_id: supporter.id,
|
||||
event_id: event.id,
|
||||
token: source_token.token,
|
||||
dedication: { 'name' => 'a name', 'type' => 'honor' },
|
||||
designation: 'designation'
|
||||
|
||||
}.with_indifferent_access
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
before_each_success
|
||||
end
|
||||
|
||||
it 'has fired transaction.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:payment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_charge_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:donation_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:trx_assignment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:transaction_created, {
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'transaction.created',
|
||||
'data' => {
|
||||
'object' => transaction_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
subject
|
||||
end
|
||||
|
||||
it 'has fired stripe_transaction_charge.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:stripe_transaction_charge_created,
|
||||
{
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'stripe_transaction_charge.created',
|
||||
'data' => {
|
||||
'object' => stripe_transaction_charge_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:payment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:donation_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:trx_assignment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:transaction_created, any_args)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it 'has fired payment.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_charge_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:payment_created,
|
||||
{
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'payment.created',
|
||||
'data' => {
|
||||
'object' => stripe_transaction_charge_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:donation_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:trx_assignment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:transaction_created, any_args)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it 'has fired stripe_transaction.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_charge_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:payment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:stripe_transaction_created,
|
||||
{
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'stripe_transaction.created',
|
||||
'data' => {
|
||||
'object' => stripe_transaction_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:donation_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:trx_assignment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:transaction_created, any_args)
|
||||
subject
|
||||
end
|
||||
|
||||
it 'has fired donation.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_charge_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:payment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:donation_created,
|
||||
{
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'donation.created',
|
||||
'data' => {
|
||||
'object' => donation_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:trx_assignment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:transaction_created, any_args)
|
||||
subject
|
||||
end
|
||||
|
||||
it 'has fired trx_assignment.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_charge_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:payment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:donation_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:trx_assignment_created,
|
||||
{
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'trx_assignment.created',
|
||||
'data' => {
|
||||
'object' => donation_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:transaction_created, any_args)
|
||||
subject
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'general donations' do
|
||||
subject do
|
||||
process_general_donation do
|
||||
described_class.with_stripe(
|
||||
{
|
||||
amount: charge_amount,
|
||||
nonprofit_id: nonprofit.id,
|
||||
supporter_id: supporter.id,
|
||||
token: source_token.token,
|
||||
profile_id: profile.id,
|
||||
dedication: { 'name' => 'a name', 'type' => 'honor' },
|
||||
designation: 'designation'
|
||||
|
||||
}.with_indifferent_access
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
before_each_success
|
||||
end
|
||||
|
||||
it 'has fired transaction.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:payment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_charge_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:donation_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:trx_assignment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:transaction_created, {
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'transaction.created',
|
||||
'data' => {
|
||||
'object' => transaction_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
subject
|
||||
end
|
||||
|
||||
it 'has fired stripe_transaction_charge.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:stripe_transaction_charge_created,
|
||||
{
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'stripe_transaction_charge.created',
|
||||
'data' => {
|
||||
'object' => stripe_transaction_charge_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:payment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:donation_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:trx_assignment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:transaction_created, any_args)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it 'has fired payment.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_charge_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:payment_created,
|
||||
{
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'payment.created',
|
||||
'data' => {
|
||||
'object' => stripe_transaction_charge_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:donation_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:trx_assignment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:transaction_created, any_args)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it 'has fired stripe_transaction.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_charge_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:payment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:stripe_transaction_created,
|
||||
{
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'stripe_transaction.created',
|
||||
'data' => {
|
||||
'object' => stripe_transaction_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:donation_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:trx_assignment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:transaction_created, any_args)
|
||||
subject
|
||||
end
|
||||
|
||||
it 'has fired donation.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_charge_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:payment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:donation_created,
|
||||
{
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'donation.created',
|
||||
'data' => {
|
||||
'object' => donation_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:trx_assignment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:transaction_created, any_args)
|
||||
subject
|
||||
end
|
||||
|
||||
it 'has fired trx_assignment.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_charge_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:payment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:donation_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:trx_assignment_created,
|
||||
{
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'trx_assignment.created',
|
||||
'data' => {
|
||||
'object' => donation_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:transaction_created, any_args)
|
||||
subject
|
||||
end
|
||||
end
|
||||
|
||||
describe 'campaign donations' do
|
||||
subject do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:campaign_create, any_args)
|
||||
process_campaign_donation do
|
||||
described_class.with_stripe(
|
||||
{
|
||||
amount: charge_amount,
|
||||
nonprofit_id: nonprofit.id,
|
||||
supporter_id: supporter.id,
|
||||
token: source_token.token,
|
||||
dedication: { 'name' => 'a name', 'type' => 'honor' },
|
||||
designation: 'designation',
|
||||
campaign_id: campaign.id
|
||||
}.with_indifferent_access
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
before_each_success
|
||||
end
|
||||
|
||||
it 'has fired transaction.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:payment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_charge_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:donation_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:trx_assignment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:transaction_created, {
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'transaction.created',
|
||||
'data' => {
|
||||
'object' => transaction_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
subject
|
||||
end
|
||||
|
||||
it 'has fired stripe_transaction_charge.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:stripe_transaction_charge_created,
|
||||
{
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'stripe_transaction_charge.created',
|
||||
'data' => {
|
||||
'object' => stripe_transaction_charge_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:payment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:donation_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:trx_assignment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:transaction_created, any_args)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it 'has fired payment.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_charge_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:payment_created,
|
||||
{
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'payment.created',
|
||||
'data' => {
|
||||
'object' => stripe_transaction_charge_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:donation_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:trx_assignment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:transaction_created, any_args)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it 'has fired stripe_transaction.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_charge_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:payment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:stripe_transaction_created,
|
||||
{
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'stripe_transaction.created',
|
||||
'data' => {
|
||||
'object' => stripe_transaction_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:donation_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:trx_assignment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:transaction_created, any_args)
|
||||
subject
|
||||
end
|
||||
|
||||
it 'has fired donation.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_charge_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:payment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:donation_created,
|
||||
{
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'donation.created',
|
||||
'data' => {
|
||||
'object' => donation_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:trx_assignment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:transaction_created, any_args)
|
||||
subject
|
||||
end
|
||||
|
||||
it 'has fired trx_assignment.created' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_charge_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:payment_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:stripe_transaction_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:donation_created, any_args)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(
|
||||
:trx_assignment_created,
|
||||
{
|
||||
'id' => match_houid('objevt'),
|
||||
'object' => 'object_event',
|
||||
'type' => 'trx_assignment.created',
|
||||
'data' => {
|
||||
'object' => donation_builder_expanded
|
||||
}
|
||||
}
|
||||
)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:transaction_created, any_args)
|
||||
subject
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#with_sepa' do
|
||||
|
|
9
spec/models/stripe_charge_spec.rb
Normal file
9
spec/models/stripe_charge_spec.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
||||
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe StripeCharge, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
9
spec/models/stripe_transaction_spec.rb
Normal file
9
spec/models/stripe_transaction_spec.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
||||
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe StripeTransaction, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in a new issue