-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
171 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
## [0.1.1] - 2023-12-11 | ||
### Added | ||
- Scope for Lago payment methods with a given provider. | ||
- Method to find a Lago payment method by provider, and provider id. | ||
- Added `pull!` and `push!` methods to billable, and payment method, to better control syncing with Lago. | ||
- Method to retrieve a payment method on billable. | ||
|
||
### Changed | ||
- Dependency `lago-ruby-client` was upgraded to version 0.52.2.pre.beta. | ||
- Improved API for adding a payment method to billable. | ||
- Method `subscription` on subscription can be passed `reload: true` to reload the subscription data. | ||
|
||
## [0.1.0] - 2023-10-23 | ||
- Initial release |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Payment Methods | ||
|
||
## Adding a Payment Method to a Customer | ||
|
||
Lago uses the default method of payment for a given customer. As such, Payment Methods in this gem actually | ||
store customer information of the given provider, rather than the payment method itself. | ||
|
||
```ruby | ||
# Adding a Stripe customer as a Payment Method | ||
customer = Pay::Customer.find(1234) | ||
customer.add_payment_method(:stripe, "cus_1234") | ||
``` | ||
|
||
```ruby | ||
# Adding a Stripe customer as a Payment Method, but make it not the default. | ||
customer = Pay::Customer.find(1234) | ||
customer.add_payment_method(:stripe, "cus_1234", default: false) | ||
``` | ||
|
||
```ruby | ||
# Adding a Stripe customer as a Payment Method, but make it not sync with Lago. | ||
# NOTE: Syncing with Lago will only work anyways if default is true (which it is by default). | ||
customer = Pay::Customer.find(1234) | ||
customer.add_payment_method(:stripe, "cus_1234", sync: false) | ||
``` | ||
|
||
## Retrieving a Payment Method | ||
|
||
```ruby | ||
# Retrieve a Payment Method with a given ID. | ||
customer = Pay::Customer.find(1234) | ||
customer.get_payment_method(:stripe, "cus_1234") | ||
``` | ||
|
||
```ruby | ||
# If no Payment Method ID is given, it will return either the first Payment Method | ||
# for the customer with the given provider, or the default Payment Method (if provider matches). | ||
customer = Pay::Customer.find(1234) | ||
customer.get_payment_method(:stripe) | ||
``` |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
class CreatePayTables < ActiveRecord::Migration[6.0] | ||
def change | ||
primary_key_type, foreign_key_type = primary_and_foreign_key_types | ||
|
||
create_table :pay_customers, id: primary_key_type do |t| | ||
t.belongs_to :owner, polymorphic: true, index: false, type: foreign_key_type | ||
t.string :processor, null: false | ||
t.string :processor_id | ||
t.boolean :default | ||
t.public_send Pay::Adapter.json_column_type, :data | ||
t.datetime :deleted_at | ||
t.string :stripe_account | ||
t.timestamps | ||
end | ||
add_index :pay_customers, [:owner_type, :owner_id, :deleted_at], name: :pay_customer_owner_index, unique: true | ||
add_index :pay_customers, [:processor, :processor_id], unique: true | ||
|
||
create_table :pay_merchants, id: primary_key_type do |t| | ||
t.belongs_to :owner, polymorphic: true, index: false, type: foreign_key_type | ||
t.string :processor, null: false | ||
t.string :processor_id | ||
t.boolean :default | ||
t.public_send Pay::Adapter.json_column_type, :data | ||
t.timestamps | ||
end | ||
add_index :pay_merchants, [:owner_type, :owner_id, :processor] | ||
|
||
create_table :pay_payment_methods, id: primary_key_type do |t| | ||
t.belongs_to :customer, foreign_key: {to_table: :pay_customers}, null: false, index: false, type: foreign_key_type | ||
t.string :processor_id, null: false | ||
t.boolean :default | ||
t.string :type | ||
t.public_send Pay::Adapter.json_column_type, :data | ||
t.timestamps | ||
end | ||
add_index :pay_payment_methods, [:customer_id, :processor_id], unique: true | ||
|
||
create_table :pay_subscriptions, id: primary_key_type do |t| | ||
t.belongs_to :customer, foreign_key: {to_table: :pay_customers}, null: false, index: false, type: foreign_key_type | ||
t.string :name, null: false | ||
t.string :processor_id, null: false | ||
t.string :processor_plan, null: false | ||
t.integer :quantity, default: 1, null: false | ||
t.string :status, null: false | ||
t.datetime :current_period_start | ||
t.datetime :current_period_end | ||
t.datetime :trial_ends_at | ||
t.datetime :ends_at | ||
t.boolean :metered | ||
t.string :pause_behavior | ||
t.datetime :pause_starts_at | ||
t.datetime :pause_resumes_at | ||
t.decimal :application_fee_percent, precision: 8, scale: 2 | ||
t.public_send Pay::Adapter.json_column_type, :metadata | ||
t.public_send Pay::Adapter.json_column_type, :data | ||
t.timestamps | ||
end | ||
add_index :pay_subscriptions, [:customer_id, :processor_id], unique: true | ||
add_index :pay_subscriptions, [:metered] | ||
add_index :pay_subscriptions, [:pause_starts_at] | ||
|
||
create_table :pay_charges, id: primary_key_type do |t| | ||
t.belongs_to :customer, foreign_key: {to_table: :pay_customers}, null: false, index: false, type: foreign_key_type | ||
t.belongs_to :subscription, foreign_key: {to_table: :pay_subscriptions}, null: true, type: foreign_key_type | ||
t.string :processor_id, null: false | ||
t.integer :amount, null: false | ||
t.string :currency | ||
t.integer :application_fee_amount | ||
t.integer :amount_refunded | ||
t.public_send Pay::Adapter.json_column_type, :metadata | ||
t.public_send Pay::Adapter.json_column_type, :data | ||
t.timestamps | ||
end | ||
add_index :pay_charges, [:customer_id, :processor_id], unique: true | ||
|
||
create_table :pay_webhooks, id: primary_key_type do |t| | ||
t.string :processor | ||
t.string :event_type | ||
t.public_send Pay::Adapter.json_column_type, :event | ||
t.timestamps | ||
end | ||
end | ||
|
||
private | ||
|
||
def primary_and_foreign_key_types | ||
config = Rails.configuration.generators | ||
setting = config.options[config.orm][:primary_key_type] | ||
primary_key_type = setting || :primary_key | ||
foreign_key_type = setting || :bigint | ||
[primary_key_type, foreign_key_type] | ||
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