1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-19 13:54:25 +01:00

stave start date in subscription schedule

This commit is contained in:
Sylvain 2021-10-18 15:19:58 +02:00
parent d0eebddcee
commit 1a672b0644
5 changed files with 25 additions and 15 deletions

View File

@ -18,7 +18,6 @@ Metrics/BlockLength:
- 'app/pdfs/pdf/*.rb'
- 'test/**/*.rb'
Metrics/ParameterLists:
Max: 6
CountKeywordArgs: false
Style/BracesAroundHashParameters:
EnforcedStyle: context_dependent

View File

@ -47,6 +47,7 @@ class PaymentScheduleService
details: details
)
end
ps.start_at = start_at
ps.total = items.map(&:amount).reduce(:+)
ps.invoicing_profile = customer.invoicing_profile
ps.statistic_profile = customer.statistic_profile

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
# From this migration, we allow PaymentSchedules to start later, previously the started
# as soon as they were created.
class AddStartAtToPaymentSchedule < ActiveRecord::Migration[5.2]
def change
add_column :payment_schedules, :start_at, :datetime
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_10_14_135151) do
ActiveRecord::Schema.define(version: 2021_10_18_121822) do
# These are extensions that must be enabled in order to support this database
enable_extension "fuzzystrmatch"
@ -19,8 +19,8 @@ ActiveRecord::Schema.define(version: 2021_10_14_135151) do
enable_extension "unaccent"
create_table "abuses", id: :serial, force: :cascade do |t|
t.string "signaled_type"
t.integer "signaled_id"
t.string "signaled_type"
t.string "first_name"
t.string "last_name"
t.string "email"
@ -49,8 +49,8 @@ ActiveRecord::Schema.define(version: 2021_10_14_135151) do
t.string "locality"
t.string "country"
t.string "postal_code"
t.string "placeable_type"
t.integer "placeable_id"
t.string "placeable_type"
t.datetime "created_at"
t.datetime "updated_at"
end
@ -64,8 +64,8 @@ ActiveRecord::Schema.define(version: 2021_10_14_135151) do
end
create_table "assets", id: :serial, force: :cascade do |t|
t.string "viewable_type"
t.integer "viewable_id"
t.string "viewable_type"
t.string "attachment"
t.string "type"
t.datetime "created_at"
@ -133,8 +133,8 @@ ActiveRecord::Schema.define(version: 2021_10_14_135151) do
end
create_table "credits", id: :serial, force: :cascade do |t|
t.string "creditable_type"
t.integer "creditable_id"
t.string "creditable_type"
t.integer "plan_id"
t.integer "hours"
t.datetime "created_at"
@ -356,15 +356,15 @@ ActiveRecord::Schema.define(version: 2021_10_14_135151) do
create_table "notifications", id: :serial, force: :cascade do |t|
t.integer "receiver_id"
t.string "attached_object_type"
t.integer "attached_object_id"
t.string "attached_object_type"
t.integer "notification_type_id"
t.boolean "is_read", default: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "receiver_type"
t.boolean "is_send", default: false
t.jsonb "meta_data", default: "{}"
t.jsonb "meta_data", default: {}
t.index ["notification_type_id"], name: "index_notifications_on_notification_type_id"
t.index ["receiver_id"], name: "index_notifications_on_receiver_id"
end
@ -479,6 +479,7 @@ ActiveRecord::Schema.define(version: 2021_10_14_135151) do
t.bigint "operator_profile_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "start_at"
t.index ["coupon_id"], name: "index_payment_schedules_on_coupon_id"
t.index ["invoicing_profile_id"], name: "index_payment_schedules_on_invoicing_profile_id"
t.index ["operator_profile_id"], name: "index_payment_schedules_on_operator_profile_id"
@ -548,8 +549,8 @@ ActiveRecord::Schema.define(version: 2021_10_14_135151) do
create_table "prices", id: :serial, force: :cascade do |t|
t.integer "group_id"
t.integer "plan_id"
t.string "priceable_type"
t.integer "priceable_id"
t.string "priceable_type"
t.integer "amount"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
@ -658,8 +659,8 @@ ActiveRecord::Schema.define(version: 2021_10_14_135151) do
t.text "message"
t.datetime "created_at"
t.datetime "updated_at"
t.string "reservable_type"
t.integer "reservable_id"
t.string "reservable_type"
t.integer "nb_reserve_places"
t.integer "statistic_profile_id"
t.index ["reservable_type", "reservable_id"], name: "index_reservations_on_reservable_type_and_reservable_id"
@ -668,8 +669,8 @@ ActiveRecord::Schema.define(version: 2021_10_14_135151) do
create_table "roles", id: :serial, force: :cascade do |t|
t.string "name"
t.string "resource_type"
t.integer "resource_id"
t.string "resource_type"
t.datetime "created_at"
t.datetime "updated_at"
t.index ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id"

View File

@ -28,7 +28,7 @@ class Stripe::Service < Payment::Service
# other items (not recurring)
items = subscription_invoice_items(payment_schedule, subscription, first_item, reservable_stp_id)
create_remote_subscription(shopping_cart, payment_schedule, items, price, payment_method_id, subscription)
create_remote_subscription(shopping_cart, payment_schedule, items, price, payment_method_id)
end
def create_subscription(payment_schedule, stp_object_id, stp_object_type)
@ -154,9 +154,9 @@ class Stripe::Service < Payment::Service
# Create the provided PaymentSchedule on Stripe, using the Subscription API
def create_remote_subscription(shopping_cart, payment_schedule, items, price, payment_method_id, subscription)
def create_remote_subscription(shopping_cart, payment_schedule, items, price, payment_method_id)
stripe_key = Setting.get('stripe_secret_key')
if subscription.start_at.nil?
if payment_schedule.start_at.nil?
Stripe::Subscription.create({
customer: shopping_cart.customer.payment_gateway_object.gateway_object_id,
cancel_at: (payment_schedule.payment_schedule_items.max_by(&:due_date).due_date + 1.month).to_i,
@ -171,7 +171,7 @@ class Stripe::Service < Payment::Service
else
Stripe::SubscriptionSchedule.create({
customer: shopping_cart.customer.payment_gateway_object.gateway_object_id,
start_date: subscription.start_at.to_i,
start_date: payment_schedule.start_at.to_i,
end_behavior: 'cancel',
phases: [
{