Skip to content
Open
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
6 changes: 6 additions & 0 deletions db/migrate/20191206144712_add_columns_to_charges.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddColumnsToCharges < ActiveRecord::Migration[5.2]
def change
add_column :pay_charges, :payment_intent, :string
add_column :pay_charges, :captured, :boolean
end
end
4 changes: 4 additions & 0 deletions lib/pay/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def setup_intent?
intent.is_a?(::Stripe::SetupIntent)
end

def capture
intent.capture
end

def validate
if requires_payment_method?
raise Pay::InvalidPaymentMethod.new(self)
Expand Down
16 changes: 16 additions & 0 deletions lib/pay/stripe/charge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,28 @@ def stripe?
processor == "stripe"
end

# Doesn't work in jumpstartpro
# #######
# Team.first.charges.first.stripe_charge
# > NoMethodError: undefined method `retrieve' for Pay::Stripe::Charge:Module
def stripe_charge
Stripe::Charge.retrieve(processor_id)
rescue ::Stripe::StripeError => e
raise Error, e.message
end

# To capture a Charge created through a PaymentIntent we have to capture the PaymentIntent itself.
# #######
# Stripe::Charge.retrieve(processor_id).capture
# > Stripe::InvalidRequestError: This uncaptured Charge was created by a PaymentIntent. You must capture the PaymentIntent instead.
def stripe_capture
Pay::Payment.from_id(payment_intent).capture
update(captured: true)

rescue ::Stripe::StripeError => e
raise Error, e.message
end

def stripe_refund!(amount_to_refund)
Stripe::Refund.create(
charge: processor_id,
Expand Down
4 changes: 3 additions & 1 deletion test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_08_16_015720) do
ActiveRecord::Schema.define(version: 2019_12_06_144712) do

create_table "pay_charges", force: :cascade do |t|
t.integer "owner_id"
Expand All @@ -24,6 +24,8 @@
t.string "card_exp_year"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "payment_intent"
t.boolean "captured"
t.index ["owner_id"], name: "index_pay_charges_on_owner_id"
end

Expand Down