mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
(test) test admin reserves for himself
This commit is contained in:
parent
744b811b62
commit
c9901a89e1
@ -31,6 +31,9 @@
|
||||
<td>{{ admin.email }}</td>
|
||||
<td>{{ admin.profile_attributes.phone }}</td>
|
||||
<td>
|
||||
<button class="btn btn-default edit-member" ui-sref="app.admin.members_edit({id: admin.id})">
|
||||
<i class="fa fa-edit"></i>
|
||||
</button>
|
||||
<button class="btn btn-danger" ng-if="isAuthorized('admin') && admin.id != currentUser.id" ng-click="destroyAdmin(admins, admin)">
|
||||
<i class="fa fa-trash-o"></i>
|
||||
</button>
|
||||
|
@ -6,6 +6,6 @@ class LocalPaymentPolicy < ApplicationPolicy
|
||||
# only admins and managers can offer free extensions of a subscription
|
||||
has_free_days = record.shopping_cart.items.any? { |item| item.is_a? CartItem::FreeExtension }
|
||||
|
||||
user.admin? || (user.manager? && record.shopping_cart.customer.id != user.id) || (record.price.zero? && !has_free_days)
|
||||
((user.admin? || user.manager?) && record.shopping_cart.customer.id != user.id) || (record.price.zero? && !has_free_days)
|
||||
end
|
||||
end
|
||||
|
12
test/fixtures/addresses.yml
vendored
12
test/fixtures/addresses.yml
vendored
@ -86,3 +86,15 @@ address_7:
|
||||
placeable_type: InvoicingProfile
|
||||
created_at: 2016-08-02 11:16:24.412236000 Z
|
||||
updated_at: 2016-08-02 11:16:24.412236000 Z
|
||||
|
||||
address_8:
|
||||
id: 8
|
||||
address: 127 allée des armées en déroute, 17120 SEMUSSAC
|
||||
street_number:
|
||||
route:
|
||||
locality:
|
||||
postal_code:
|
||||
placeable_id: 1
|
||||
placeable_type: InvoicingProfile
|
||||
created_at: 2016-08-02 11:16:24.412236000 Z
|
||||
updated_at: 2016-08-02 11:16:24.412236000 Z
|
||||
|
7
test/fixtures/groups.yml
vendored
7
test/fixtures/groups.yml
vendored
@ -11,10 +11,3 @@ group_2:
|
||||
created_at: 2016-04-04 14:11:33.656537000 Z
|
||||
updated_at: 2016-04-04 14:11:33.656537000 Z
|
||||
slug: student
|
||||
|
||||
admins:
|
||||
id: 3
|
||||
name: Administrateurs
|
||||
created_at: 2017-09-18 10:24:33.651615210 Z
|
||||
updated_at: 2017-09-18 10:24:33.651615210 Z
|
||||
slug: admins
|
2
test/fixtures/statistic_profiles.yml
vendored
2
test/fixtures/statistic_profiles.yml
vendored
@ -3,7 +3,7 @@ admin:
|
||||
user_id: 1
|
||||
gender: true
|
||||
birthday: 2016-04-04
|
||||
group_id: 3
|
||||
group_id: 1
|
||||
|
||||
jdupont:
|
||||
id: 2
|
||||
|
2
test/fixtures/users.yml
vendored
2
test/fixtures/users.yml
vendored
@ -21,7 +21,7 @@ user_1:
|
||||
created_at: 2001-01-01 14:11:33.852719000 Z
|
||||
updated_at: 2016-04-05 08:36:08.362215000 Z
|
||||
is_allow_contact: true
|
||||
group_id: 3
|
||||
group_id: 1
|
||||
slug: admin
|
||||
is_active: true
|
||||
provider:
|
||||
|
@ -1,581 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
module Reservations; end
|
||||
|
||||
class Reservations::CreateAsAdminTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user_without_subscription = User.members.without_subscription.first
|
||||
@user_with_subscription = User.members.with_subscription.second
|
||||
@admin = User.with_role(:admin).first
|
||||
login_as(@admin, scope: :user)
|
||||
end
|
||||
|
||||
test 'user without subscription reserves a machine with success' do
|
||||
machine = Machine.find(6)
|
||||
availability = machine.availabilities.first
|
||||
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
users_credit_count = UsersCredit.count
|
||||
|
||||
post '/api/local_payment/confirm_payment', params: {
|
||||
customer_id: @user_without_subscription.id,
|
||||
items: [
|
||||
{
|
||||
reservation: {
|
||||
reservable_id: machine.id,
|
||||
reservable_type: machine.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}.to_json, headers: default_headers
|
||||
|
||||
# general assertions
|
||||
assert_equal 201, response.status
|
||||
assert_equal reservations_count + 1, Reservation.count
|
||||
assert_equal invoice_count + 1, Invoice.count
|
||||
assert_equal invoice_items_count + 1, InvoiceItem.count
|
||||
assert_equal users_credit_count, UsersCredit.count
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 0, @user_without_subscription.subscriptions.count
|
||||
assert_nil @user_without_subscription.subscribed_plan
|
||||
|
||||
# reservation assertions
|
||||
reservation = Reservation.last
|
||||
|
||||
assert reservation.original_invoice
|
||||
assert_equal 1, reservation.original_invoice.invoice_items.count
|
||||
|
||||
# invoice assertions
|
||||
invoice = reservation.original_invoice
|
||||
|
||||
assert invoice.payment_gateway_object.blank?
|
||||
refute invoice.total.blank?
|
||||
|
||||
# invoice_items assertions
|
||||
invoice_item = InvoiceItem.last
|
||||
|
||||
assert_equal machine.prices.find_by(group_id: @user_without_subscription.group_id, plan_id: nil).amount, invoice_item.amount
|
||||
|
||||
# invoice assertions
|
||||
item = InvoiceItem.find_by(object: reservation)
|
||||
invoice = item.invoice
|
||||
assert_invoice_pdf invoice
|
||||
assert_not_nil invoice.debug_footprint
|
||||
|
||||
# notification
|
||||
assert_not_empty Notification.where(attached_object: reservation)
|
||||
end
|
||||
|
||||
test 'user without subscription reserves a training with success' do
|
||||
training = Training.first
|
||||
availability = training.availabilities.first
|
||||
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
|
||||
post '/api/local_payment/confirm_payment', params: {
|
||||
customer_id: @user_without_subscription.id,
|
||||
items: [
|
||||
reservation: {
|
||||
reservable_id: training.id,
|
||||
reservable_type: training.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}.to_json, headers: default_headers
|
||||
|
||||
# general assertions
|
||||
assert_equal 201, response.status
|
||||
assert_equal reservations_count + 1, Reservation.count
|
||||
assert_equal invoice_count + 1, Invoice.count
|
||||
assert_equal invoice_items_count + 1, InvoiceItem.count
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 0, @user_without_subscription.subscriptions.count
|
||||
assert_nil @user_without_subscription.subscribed_plan
|
||||
|
||||
# reservation assertions
|
||||
reservation = Reservation.last
|
||||
|
||||
assert reservation.original_invoice
|
||||
assert_equal 1, reservation.original_invoice.invoice_items.count
|
||||
|
||||
# invoice assertions
|
||||
invoice = reservation.original_invoice
|
||||
|
||||
assert invoice.payment_gateway_object.blank?
|
||||
refute invoice.total.blank?
|
||||
# invoice_items
|
||||
invoice_item = InvoiceItem.last
|
||||
|
||||
assert_equal invoice_item.amount, training.amount_by_group(@user_without_subscription.group_id).amount
|
||||
|
||||
# invoice assertions
|
||||
item = InvoiceItem.find_by(object: reservation)
|
||||
invoice = item.invoice
|
||||
assert_invoice_pdf invoice
|
||||
assert_not_nil invoice.debug_footprint
|
||||
|
||||
# notification
|
||||
assert_not_empty Notification.where(attached_object: reservation)
|
||||
end
|
||||
|
||||
test 'user with subscription reserves a machine with success' do
|
||||
plan = @user_with_subscription.subscribed_plan
|
||||
machine = Machine.find(6)
|
||||
availability = machine.availabilities.first
|
||||
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
users_credit_count = UsersCredit.count
|
||||
|
||||
post '/api/local_payment/confirm_payment', params: {
|
||||
customer_id: @user_with_subscription.id,
|
||||
items: [
|
||||
{
|
||||
reservation: {
|
||||
reservable_id: machine.id,
|
||||
reservable_type: machine.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id
|
||||
},
|
||||
{
|
||||
slot_id: availability.slots.last.id
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}.to_json, headers: default_headers
|
||||
|
||||
# general assertions
|
||||
assert_equal 201, response.status
|
||||
assert_equal reservations_count + 1, Reservation.count
|
||||
assert_equal invoice_count + 1, Invoice.count
|
||||
assert_equal invoice_items_count + 2, InvoiceItem.count
|
||||
assert_equal users_credit_count + 1, UsersCredit.count
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 1, @user_with_subscription.subscriptions.count
|
||||
assert_not_nil @user_with_subscription.subscribed_plan
|
||||
assert_equal plan.id, @user_with_subscription.subscribed_plan.id
|
||||
|
||||
# reservation assertions
|
||||
reservation = Reservation.last
|
||||
|
||||
assert reservation.original_invoice
|
||||
assert_equal 2, reservation.original_invoice.invoice_items.count
|
||||
|
||||
# invoice assertions
|
||||
invoice = reservation.original_invoice
|
||||
|
||||
assert invoice.payment_gateway_object.blank?
|
||||
refute invoice.total.blank?
|
||||
|
||||
# invoice_items assertions
|
||||
invoice_items = InvoiceItem.last(2)
|
||||
machine_price = machine.prices.find_by(group_id: @user_with_subscription.group_id, plan_id: plan.id).amount
|
||||
|
||||
assert(invoice_items.any? { |ii| ii.amount.zero? })
|
||||
assert(invoice_items.any? { |ii| ii.amount == machine_price })
|
||||
|
||||
# users_credits assertions
|
||||
users_credit = UsersCredit.last
|
||||
|
||||
assert_equal @user_with_subscription, users_credit.user
|
||||
assert_equal [reservation.slots.count, plan.machine_credits.find_by(creditable_id: machine.id).hours].min, users_credit.hours_used
|
||||
|
||||
# invoice assertions
|
||||
item = InvoiceItem.find_by(object: reservation)
|
||||
invoice = item.invoice
|
||||
assert_invoice_pdf invoice
|
||||
assert_not_nil invoice.debug_footprint
|
||||
|
||||
# notification
|
||||
assert_not_empty Notification.where(attached_object: reservation)
|
||||
end
|
||||
|
||||
test 'user without subscription reserves a machine and pay by wallet with success' do
|
||||
@vlonchamp = User.find_by(username: 'vlonchamp')
|
||||
machine = Machine.find(6)
|
||||
availability = machine.availabilities.first
|
||||
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
users_credit_count = UsersCredit.count
|
||||
|
||||
post '/api/local_payment/confirm_payment', params: {
|
||||
customer_id: @vlonchamp.id,
|
||||
items: [
|
||||
{
|
||||
reservation: {
|
||||
reservable_id: machine.id,
|
||||
reservable_type: machine.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}.to_json, headers: default_headers
|
||||
|
||||
# general assertions
|
||||
assert_equal 201, response.status
|
||||
assert_equal reservations_count + 1, Reservation.count
|
||||
assert_equal invoice_count + 1, Invoice.count
|
||||
assert_equal invoice_items_count + 1, InvoiceItem.count
|
||||
assert_equal users_credit_count, UsersCredit.count
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 0, @user_without_subscription.subscriptions.count
|
||||
assert_nil @user_without_subscription.subscribed_plan
|
||||
|
||||
# reservation assertions
|
||||
reservation = Reservation.last
|
||||
|
||||
assert reservation.original_invoice
|
||||
assert_equal 1, reservation.original_invoice.invoice_items.count
|
||||
|
||||
# invoice assertions
|
||||
invoice = reservation.original_invoice
|
||||
|
||||
assert invoice.payment_gateway_object.blank?
|
||||
refute invoice.total.blank?
|
||||
|
||||
# invoice_items assertions
|
||||
invoice_item = InvoiceItem.last
|
||||
|
||||
assert_equal machine.prices.find_by(group_id: @vlonchamp.group_id, plan_id: nil).amount, invoice_item.amount
|
||||
|
||||
# invoice assertions
|
||||
item = InvoiceItem.find_by(object: reservation)
|
||||
invoice = item.invoice
|
||||
assert_invoice_pdf invoice
|
||||
assert_not_nil invoice.debug_footprint
|
||||
|
||||
# notification
|
||||
assert_not_empty Notification.where(attached_object: reservation)
|
||||
|
||||
# wallet
|
||||
assert_equal @vlonchamp.wallet.amount, 0
|
||||
assert_equal @vlonchamp.wallet.wallet_transactions.count, 2
|
||||
transaction = @vlonchamp.wallet.wallet_transactions.last
|
||||
assert_equal transaction.transaction_type, 'debit'
|
||||
assert_equal transaction.amount, 10
|
||||
assert_equal transaction.amount, invoice.wallet_amount / 100.0
|
||||
assert_equal transaction.id, invoice.wallet_transaction_id
|
||||
end
|
||||
|
||||
test 'user reserves a machine and a subscription pay by wallet with success' do
|
||||
@vlonchamp = User.find_by(username: 'vlonchamp')
|
||||
machine = Machine.find(6)
|
||||
availability = machine.availabilities.first
|
||||
plan = Plan.find_by(group_id: @vlonchamp.group.id, type: 'Plan', base_name: 'Mensuel tarif réduit')
|
||||
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
users_credit_count = UsersCredit.count
|
||||
wallet_transactions_count = WalletTransaction.count
|
||||
|
||||
post '/api/local_payment/confirm_payment', params: {
|
||||
customer_id: @vlonchamp.id,
|
||||
items: [
|
||||
{
|
||||
reservation: {
|
||||
reservable_id: machine.id,
|
||||
reservable_type: machine.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
subscription: {
|
||||
plan_id: plan.id
|
||||
}
|
||||
}
|
||||
]
|
||||
}.to_json, headers: default_headers
|
||||
|
||||
# general assertions
|
||||
assert_equal 201, response.status
|
||||
assert_equal reservations_count + 1, Reservation.count
|
||||
assert_equal invoice_count + 1, Invoice.count
|
||||
assert_equal invoice_items_count + 2, InvoiceItem.count
|
||||
assert_equal users_credit_count + 1, UsersCredit.count
|
||||
assert_equal wallet_transactions_count + 1, WalletTransaction.count
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 1, @vlonchamp.subscriptions.count
|
||||
assert_not_nil @vlonchamp.subscribed_plan
|
||||
assert_equal plan.id, @vlonchamp.subscribed_plan.id
|
||||
|
||||
# reservation assertions
|
||||
reservation = Reservation.last
|
||||
|
||||
assert reservation.original_invoice
|
||||
assert_equal 2, reservation.original_invoice.invoice_items.count
|
||||
|
||||
# invoice assertions
|
||||
invoice = reservation.original_invoice
|
||||
|
||||
assert invoice.payment_gateway_object.blank?
|
||||
refute invoice.total.blank?
|
||||
assert_equal invoice.total, 2000
|
||||
|
||||
# invoice assertions
|
||||
item = InvoiceItem.find_by(object: reservation)
|
||||
invoice = item.invoice
|
||||
assert_invoice_pdf invoice
|
||||
assert_not_nil invoice.debug_footprint
|
||||
|
||||
# notification
|
||||
assert_not_empty Notification.where(attached_object: reservation)
|
||||
|
||||
# wallet
|
||||
assert_equal @vlonchamp.wallet.amount, 0
|
||||
assert_equal @vlonchamp.wallet.wallet_transactions.count, 2
|
||||
transaction = @vlonchamp.wallet.wallet_transactions.last
|
||||
assert_equal transaction.transaction_type, 'debit'
|
||||
assert_equal transaction.amount, 10
|
||||
assert_equal transaction.amount, invoice.wallet_amount / 100.0
|
||||
assert_equal transaction.id, invoice.wallet_transaction_id
|
||||
end
|
||||
|
||||
test 'user without subscription reserves a machine and pay wallet with success' do
|
||||
@vlonchamp = User.find_by(username: 'vlonchamp')
|
||||
machine = Machine.find(6)
|
||||
availability = machine.availabilities.first
|
||||
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
users_credit_count = UsersCredit.count
|
||||
|
||||
post '/api/local_payment/confirm_payment', params: {
|
||||
customer_id: @vlonchamp.id,
|
||||
items: [
|
||||
{
|
||||
reservation: {
|
||||
reservable_id: machine.id,
|
||||
reservable_type: machine.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}.to_json, headers: default_headers
|
||||
|
||||
# general assertions
|
||||
assert_equal 201, response.status
|
||||
assert_equal reservations_count + 1, Reservation.count
|
||||
assert_equal invoice_count + 1, Invoice.count
|
||||
assert_equal invoice_items_count + 1, InvoiceItem.count
|
||||
assert_equal users_credit_count, UsersCredit.count
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 0, @vlonchamp.subscriptions.count
|
||||
assert_nil @vlonchamp.subscribed_plan
|
||||
|
||||
# reservation assertions
|
||||
reservation = Reservation.last
|
||||
|
||||
assert_not_nil reservation.original_invoice
|
||||
|
||||
# notification
|
||||
assert_not_empty Notification.where(attached_object: reservation)
|
||||
end
|
||||
|
||||
test 'user reserves a training and a subscription with success' do
|
||||
training = Training.first
|
||||
availability = training.availabilities.first
|
||||
plan = Plan.where(group_id: @user_without_subscription.group.id, type: 'Plan').first
|
||||
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
users_credit_count = UsersCredit.count
|
||||
|
||||
post '/api/local_payment/confirm_payment', params: {
|
||||
customer_id: @user_without_subscription.id,
|
||||
items: [
|
||||
{
|
||||
reservation: {
|
||||
reservable_id: training.id,
|
||||
reservable_type: training.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id,
|
||||
offered: false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
subscription: {
|
||||
plan_id: plan.id
|
||||
}
|
||||
}
|
||||
]
|
||||
}.to_json, headers: default_headers
|
||||
|
||||
# general assertions
|
||||
assert_equal 201, response.status
|
||||
assert_equal Mime[:json], response.content_type
|
||||
result = json_response(response.body)
|
||||
|
||||
# Check the DB objects have been created as they should
|
||||
assert_equal reservations_count + 1, Reservation.count
|
||||
assert_equal invoice_count + 1, Invoice.count
|
||||
assert_equal invoice_items_count + 2, InvoiceItem.count
|
||||
assert_equal users_credit_count + 1, UsersCredit.count
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 1, @user_without_subscription.subscriptions.count
|
||||
assert_not_nil @user_without_subscription.subscribed_plan
|
||||
assert_equal plan.id, @user_without_subscription.subscribed_plan.id
|
||||
|
||||
# reservation assertions
|
||||
invoice = Invoice.find(result[:id])
|
||||
reservation = invoice.main_item.object
|
||||
|
||||
assert reservation.original_invoice
|
||||
assert_equal 2, reservation.original_invoice.invoice_items.count
|
||||
|
||||
# credits assertions
|
||||
assert_equal 1, @user_without_subscription.credits.count
|
||||
assert_equal 'Training', @user_without_subscription.credits.last.creditable_type
|
||||
assert_equal training.id, @user_without_subscription.credits.last.creditable_id
|
||||
|
||||
# invoice assertions
|
||||
invoice = reservation.original_invoice
|
||||
|
||||
assert invoice.payment_gateway_object.blank?
|
||||
refute invoice.total.blank?
|
||||
assert_equal plan.amount, invoice.total
|
||||
|
||||
# invoice_items
|
||||
invoice_items = InvoiceItem.last(2)
|
||||
|
||||
assert(invoice_items.any? { |ii| ii.amount == plan.amount && ii.object_type == Subscription.name })
|
||||
assert(invoice_items.any? { |ii| ii.amount.zero? })
|
||||
|
||||
# invoice assertions
|
||||
item = InvoiceItem.find_by(object: reservation)
|
||||
invoice = item.invoice
|
||||
assert_invoice_pdf invoice
|
||||
assert_not_nil invoice.debug_footprint
|
||||
|
||||
# notification
|
||||
assert_not_empty Notification.where(attached_object: reservation)
|
||||
end
|
||||
|
||||
test 'user reserves a training and a subscription with payment schedule' do
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
subscriptions_count = Subscription.count
|
||||
users_credit_count = UsersCredit.count
|
||||
payment_schedule_count = PaymentSchedule.count
|
||||
payment_schedule_items_count = PaymentScheduleItem.count
|
||||
|
||||
training = Training.find(1)
|
||||
availability = training.availabilities.first
|
||||
plan = Plan.find_by(group_id: @user_without_subscription.group.id, type: 'Plan', base_name: 'Abonnement mensualisable')
|
||||
|
||||
VCR.use_cassette('reservations_admin_training_subscription_with_payment_schedule') do
|
||||
post '/api/local_payment/confirm_payment', params: {
|
||||
payment_method: 'check',
|
||||
payment_schedule: true,
|
||||
customer_id: @user_without_subscription.id,
|
||||
items: [
|
||||
{
|
||||
reservation: {
|
||||
reservable_id: training.id,
|
||||
reservable_type: training.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
subscription: {
|
||||
plan_id: plan.id
|
||||
}
|
||||
}
|
||||
]
|
||||
}.to_json, headers: default_headers
|
||||
end
|
||||
|
||||
# get the objects
|
||||
reservation = Reservation.last
|
||||
payment_schedule = PaymentSchedule.last
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 201, response.status, response.body
|
||||
assert_equal Mime[:json], response.content_type
|
||||
assert_equal reservations_count + 1, Reservation.count, 'missing the reservation'
|
||||
assert_equal invoice_count, Invoice.count, "an invoice was generated but it shouldn't"
|
||||
assert_equal invoice_items_count, InvoiceItem.count, "some invoice items were generated but they shouldn't"
|
||||
assert_equal users_credit_count, UsersCredit.count, "user's credits count has changed but it shouldn't"
|
||||
assert_equal subscriptions_count + 1, Subscription.count, 'missing the subscription'
|
||||
assert_equal payment_schedule_count + 1, PaymentSchedule.count, 'missing the payment schedule'
|
||||
assert_equal payment_schedule_items_count + 12, PaymentScheduleItem.count, 'missing some payment schedule items'
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 1, @user_without_subscription.subscriptions.count
|
||||
assert_not_nil @user_without_subscription.subscribed_plan, "user's subscribed plan was not found"
|
||||
assert_not_nil @user_without_subscription.subscription, "user's subscription was not found"
|
||||
assert_equal plan.id, @user_without_subscription.subscribed_plan.id, "user's plan does not match"
|
||||
|
||||
# payment schedule assertions
|
||||
assert reservation.original_payment_schedule
|
||||
assert_equal payment_schedule.id, reservation.original_payment_schedule.id
|
||||
assert_not_nil payment_schedule.reference
|
||||
assert_equal 'check', payment_schedule.payment_method
|
||||
assert_empty payment_schedule.payment_gateway_objects
|
||||
assert_nil payment_schedule.wallet_transaction
|
||||
assert_nil payment_schedule.wallet_amount
|
||||
assert_nil payment_schedule.coupon_id
|
||||
assert_equal 'test', payment_schedule.environment
|
||||
assert payment_schedule.check_footprint
|
||||
assert_equal @user_without_subscription.invoicing_profile.id, payment_schedule.invoicing_profile_id
|
||||
assert_equal @admin.invoicing_profile.id, payment_schedule.operator_profile_id
|
||||
|
||||
# Check the answer
|
||||
result = json_response(response.body)
|
||||
assert_equal reservation.original_payment_schedule.id, result[:id], 'payment schedule id does not match'
|
||||
|
||||
# reservation assertions
|
||||
assert_equal result[:main_object][:id], reservation.id
|
||||
assert_equal payment_schedule.main_object.object, reservation
|
||||
end
|
||||
end
|
298
test/integration/reservations/local_payment_test.rb
Normal file
298
test/integration/reservations/local_payment_test.rb
Normal file
@ -0,0 +1,298 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
module Reservations; end
|
||||
|
||||
class Reservations::LocalPaymentTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user_without_subscription = User.members.without_subscription.first
|
||||
@user_with_subscription = User.members.with_subscription.second
|
||||
@admin = User.with_role(:admin).first
|
||||
login_as(@admin, scope: :user)
|
||||
end
|
||||
|
||||
test 'user without subscription reserves a machine with success' do
|
||||
machine = Machine.find(6)
|
||||
availability = machine.availabilities.first
|
||||
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
users_credit_count = UsersCredit.count
|
||||
|
||||
post '/api/local_payment/confirm_payment', params: {
|
||||
customer_id: @user_without_subscription.id,
|
||||
items: [
|
||||
{
|
||||
reservation: {
|
||||
reservable_id: machine.id,
|
||||
reservable_type: machine.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}.to_json, headers: default_headers
|
||||
|
||||
# general assertions
|
||||
assert_equal 201, response.status
|
||||
assert_equal reservations_count + 1, Reservation.count
|
||||
assert_equal invoice_count + 1, Invoice.count
|
||||
assert_equal invoice_items_count + 1, InvoiceItem.count
|
||||
assert_equal users_credit_count, UsersCredit.count
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 0, @user_without_subscription.subscriptions.count
|
||||
assert_nil @user_without_subscription.subscribed_plan
|
||||
|
||||
# reservation assertions
|
||||
reservation = Reservation.last
|
||||
|
||||
assert reservation.original_invoice
|
||||
assert_equal 1, reservation.original_invoice.invoice_items.count
|
||||
|
||||
# invoice assertions
|
||||
invoice = reservation.original_invoice
|
||||
|
||||
assert invoice.payment_gateway_object.blank?
|
||||
assert_not invoice.total.blank?
|
||||
|
||||
# invoice_items assertions
|
||||
invoice_item = InvoiceItem.last
|
||||
|
||||
assert_equal machine.prices.find_by(group_id: @user_without_subscription.group_id, plan_id: nil).amount, invoice_item.amount
|
||||
|
||||
# invoice assertions
|
||||
item = InvoiceItem.find_by(object: reservation)
|
||||
invoice = item.invoice
|
||||
assert_invoice_pdf invoice
|
||||
assert_not_nil invoice.debug_footprint
|
||||
|
||||
# notification
|
||||
assert_not_empty Notification.where(attached_object: reservation)
|
||||
end
|
||||
|
||||
test 'user without subscription reserves a training with success' do
|
||||
training = Training.first
|
||||
availability = training.availabilities.first
|
||||
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
|
||||
post '/api/local_payment/confirm_payment', params: {
|
||||
customer_id: @user_without_subscription.id,
|
||||
items: [
|
||||
reservation: {
|
||||
reservable_id: training.id,
|
||||
reservable_type: training.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}.to_json, headers: default_headers
|
||||
|
||||
# general assertions
|
||||
assert_equal 201, response.status
|
||||
assert_equal reservations_count + 1, Reservation.count
|
||||
assert_equal invoice_count + 1, Invoice.count
|
||||
assert_equal invoice_items_count + 1, InvoiceItem.count
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 0, @user_without_subscription.subscriptions.count
|
||||
assert_nil @user_without_subscription.subscribed_plan
|
||||
|
||||
# reservation assertions
|
||||
reservation = Reservation.last
|
||||
|
||||
assert reservation.original_invoice
|
||||
assert_equal 1, reservation.original_invoice.invoice_items.count
|
||||
|
||||
# invoice assertions
|
||||
invoice = reservation.original_invoice
|
||||
|
||||
assert invoice.payment_gateway_object.blank?
|
||||
assert_not invoice.total.blank?
|
||||
# invoice_items
|
||||
invoice_item = InvoiceItem.last
|
||||
|
||||
assert_equal invoice_item.amount, training.amount_by_group(@user_without_subscription.group_id).amount
|
||||
|
||||
# invoice assertions
|
||||
item = InvoiceItem.find_by(object: reservation)
|
||||
invoice = item.invoice
|
||||
assert_invoice_pdf invoice
|
||||
assert_not_nil invoice.debug_footprint
|
||||
|
||||
# notification
|
||||
assert_not_empty Notification.where(attached_object: reservation)
|
||||
end
|
||||
|
||||
test 'user with subscription reserves a machine with success' do
|
||||
plan = @user_with_subscription.subscribed_plan
|
||||
machine = Machine.find(6)
|
||||
availability = machine.availabilities.first
|
||||
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
users_credit_count = UsersCredit.count
|
||||
|
||||
post '/api/local_payment/confirm_payment', params: {
|
||||
customer_id: @user_with_subscription.id,
|
||||
items: [
|
||||
{
|
||||
reservation: {
|
||||
reservable_id: machine.id,
|
||||
reservable_type: machine.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id
|
||||
},
|
||||
{
|
||||
slot_id: availability.slots.last.id
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}.to_json, headers: default_headers
|
||||
|
||||
# general assertions
|
||||
assert_equal 201, response.status
|
||||
assert_equal reservations_count + 1, Reservation.count
|
||||
assert_equal invoice_count + 1, Invoice.count
|
||||
assert_equal invoice_items_count + 2, InvoiceItem.count
|
||||
assert_equal users_credit_count + 1, UsersCredit.count
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 1, @user_with_subscription.subscriptions.count
|
||||
assert_not_nil @user_with_subscription.subscribed_plan
|
||||
assert_equal plan.id, @user_with_subscription.subscribed_plan.id
|
||||
|
||||
# reservation assertions
|
||||
reservation = Reservation.last
|
||||
|
||||
assert reservation.original_invoice
|
||||
assert_equal 2, reservation.original_invoice.invoice_items.count
|
||||
|
||||
# invoice assertions
|
||||
invoice = reservation.original_invoice
|
||||
|
||||
assert invoice.payment_gateway_object.blank?
|
||||
assert_not invoice.total.blank?
|
||||
|
||||
# invoice_items assertions
|
||||
invoice_items = InvoiceItem.last(2)
|
||||
machine_price = machine.prices.find_by(group_id: @user_with_subscription.group_id, plan_id: plan.id).amount
|
||||
|
||||
assert(invoice_items.any? { |ii| ii.amount.zero? })
|
||||
assert(invoice_items.any? { |ii| ii.amount == machine_price })
|
||||
|
||||
# users_credits assertions
|
||||
users_credit = UsersCredit.last
|
||||
|
||||
assert_equal @user_with_subscription, users_credit.user
|
||||
assert_equal [reservation.slots.count, plan.machine_credits.find_by(creditable_id: machine.id).hours].min, users_credit.hours_used
|
||||
|
||||
# invoice assertions
|
||||
item = InvoiceItem.find_by(object: reservation)
|
||||
invoice = item.invoice
|
||||
assert_invoice_pdf invoice
|
||||
assert_not_nil invoice.debug_footprint
|
||||
|
||||
# notification
|
||||
assert_not_empty Notification.where(attached_object: reservation)
|
||||
end
|
||||
|
||||
test 'user reserves a training and a subscription with success' do
|
||||
training = Training.first
|
||||
availability = training.availabilities.first
|
||||
plan = Plan.where(group_id: @user_without_subscription.group.id, type: 'Plan').first
|
||||
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
users_credit_count = UsersCredit.count
|
||||
|
||||
post '/api/local_payment/confirm_payment', params: {
|
||||
customer_id: @user_without_subscription.id,
|
||||
items: [
|
||||
{
|
||||
reservation: {
|
||||
reservable_id: training.id,
|
||||
reservable_type: training.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id,
|
||||
offered: false
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
subscription: {
|
||||
plan_id: plan&.id
|
||||
}
|
||||
}
|
||||
]
|
||||
}.to_json, headers: default_headers
|
||||
|
||||
# general assertions
|
||||
assert_equal 201, response.status
|
||||
assert_equal Mime[:json], response.content_type
|
||||
result = json_response(response.body)
|
||||
|
||||
# Check the DB objects have been created as they should
|
||||
assert_equal reservations_count + 1, Reservation.count
|
||||
assert_equal invoice_count + 1, Invoice.count
|
||||
assert_equal invoice_items_count + 2, InvoiceItem.count
|
||||
assert_equal users_credit_count + 1, UsersCredit.count
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 1, @user_without_subscription.subscriptions.count
|
||||
assert_not_nil @user_without_subscription.subscribed_plan
|
||||
assert_equal plan&.id, @user_without_subscription.subscribed_plan.id
|
||||
|
||||
# reservation assertions
|
||||
invoice = Invoice.find(result[:id])
|
||||
reservation = invoice.main_item.object
|
||||
|
||||
assert reservation.original_invoice
|
||||
assert_equal 2, reservation.original_invoice.invoice_items.count
|
||||
|
||||
# credits assertions
|
||||
assert_equal 1, @user_without_subscription.credits.count
|
||||
assert_equal 'Training', @user_without_subscription.credits.last.creditable_type
|
||||
assert_equal training.id, @user_without_subscription.credits.last.creditable_id
|
||||
|
||||
# invoice assertions
|
||||
invoice = reservation.original_invoice
|
||||
|
||||
assert invoice.payment_gateway_object.blank?
|
||||
assert_not invoice.total.blank?
|
||||
assert_equal plan&.amount, invoice.total
|
||||
|
||||
# invoice_items
|
||||
invoice_items = InvoiceItem.last(2)
|
||||
|
||||
assert(invoice_items.any? { |ii| ii.amount == plan&.amount && ii.object_type == Subscription.name })
|
||||
assert(invoice_items.any? { |ii| ii.amount.zero? })
|
||||
|
||||
# invoice assertions
|
||||
item = InvoiceItem.find_by(object: reservation)
|
||||
invoice = item.invoice
|
||||
assert_invoice_pdf invoice
|
||||
assert_not_nil invoice.debug_footprint
|
||||
|
||||
# notification
|
||||
assert_not_empty Notification.where(attached_object: reservation)
|
||||
end
|
||||
end
|
210
test/integration/reservations/local_payment_with_wallet_test.rb
Normal file
210
test/integration/reservations/local_payment_with_wallet_test.rb
Normal file
@ -0,0 +1,210 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
module Reservations; end
|
||||
|
||||
class Reservations::LocalPaymentWithWalletTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@vlonchamp = User.find_by(username: 'vlonchamp')
|
||||
@admin = User.with_role(:admin).first
|
||||
login_as(@admin, scope: :user)
|
||||
end
|
||||
|
||||
test 'user reserves a machine and a subscription pay by wallet with success' do
|
||||
machine = Machine.find(6)
|
||||
availability = machine.availabilities.first
|
||||
plan = Plan.find_by(group_id: @vlonchamp.group.id, type: 'Plan', base_name: 'Mensuel tarif réduit')
|
||||
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
users_credit_count = UsersCredit.count
|
||||
wallet_transactions_count = WalletTransaction.count
|
||||
|
||||
post '/api/local_payment/confirm_payment', params: {
|
||||
customer_id: @vlonchamp.id,
|
||||
items: [
|
||||
{
|
||||
reservation: {
|
||||
reservable_id: machine.id,
|
||||
reservable_type: machine.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
subscription: {
|
||||
plan_id: plan.id
|
||||
}
|
||||
}
|
||||
]
|
||||
}.to_json, headers: default_headers
|
||||
|
||||
# general assertions
|
||||
assert_equal 201, response.status
|
||||
assert_equal reservations_count + 1, Reservation.count
|
||||
assert_equal invoice_count + 1, Invoice.count
|
||||
assert_equal invoice_items_count + 2, InvoiceItem.count
|
||||
assert_equal users_credit_count + 1, UsersCredit.count
|
||||
assert_equal wallet_transactions_count + 1, WalletTransaction.count
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 1, @vlonchamp.subscriptions.count
|
||||
assert_not_nil @vlonchamp.subscribed_plan
|
||||
assert_equal plan.id, @vlonchamp.subscribed_plan.id
|
||||
|
||||
# reservation assertions
|
||||
reservation = Reservation.last
|
||||
|
||||
assert reservation.original_invoice
|
||||
assert_equal 2, reservation.original_invoice.invoice_items.count
|
||||
|
||||
# invoice assertions
|
||||
invoice = reservation.original_invoice
|
||||
|
||||
assert invoice.payment_gateway_object.blank?
|
||||
assert_not invoice.total.blank?
|
||||
assert_equal invoice.total, 2000
|
||||
|
||||
# invoice assertions
|
||||
item = InvoiceItem.find_by(object: reservation)
|
||||
invoice = item.invoice
|
||||
assert_invoice_pdf invoice
|
||||
assert_not_nil invoice.debug_footprint
|
||||
|
||||
# notification
|
||||
assert_not_empty Notification.where(attached_object: reservation)
|
||||
|
||||
# wallet
|
||||
assert_equal @vlonchamp.wallet.amount, 0
|
||||
assert_equal @vlonchamp.wallet.wallet_transactions.count, 2
|
||||
transaction = @vlonchamp.wallet.wallet_transactions.last
|
||||
assert_equal transaction.transaction_type, 'debit'
|
||||
assert_equal transaction.amount, 10
|
||||
assert_equal transaction.amount, invoice.wallet_amount / 100.0
|
||||
assert_equal transaction.id, invoice.wallet_transaction_id
|
||||
end
|
||||
|
||||
test 'user without subscription reserves a machine and pay wallet with success' do
|
||||
machine = Machine.find(6)
|
||||
availability = machine.availabilities.first
|
||||
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
users_credit_count = UsersCredit.count
|
||||
|
||||
post '/api/local_payment/confirm_payment', params: {
|
||||
customer_id: @vlonchamp.id,
|
||||
items: [
|
||||
{
|
||||
reservation: {
|
||||
reservable_id: machine.id,
|
||||
reservable_type: machine.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}.to_json, headers: default_headers
|
||||
|
||||
# general assertions
|
||||
assert_equal 201, response.status
|
||||
assert_equal reservations_count + 1, Reservation.count
|
||||
assert_equal invoice_count + 1, Invoice.count
|
||||
assert_equal invoice_items_count + 1, InvoiceItem.count
|
||||
assert_equal users_credit_count, UsersCredit.count
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 0, @vlonchamp.subscriptions.count
|
||||
assert_nil @vlonchamp.subscribed_plan
|
||||
|
||||
# reservation assertions
|
||||
reservation = Reservation.last
|
||||
|
||||
assert_not_nil reservation.original_invoice
|
||||
|
||||
# notification
|
||||
assert_not_empty Notification.where(attached_object: reservation)
|
||||
end
|
||||
|
||||
test 'user without subscription reserves a machine and pay by wallet with success' do
|
||||
machine = Machine.find(6)
|
||||
availability = machine.availabilities.first
|
||||
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
users_credit_count = UsersCredit.count
|
||||
|
||||
post '/api/local_payment/confirm_payment', params: {
|
||||
customer_id: @vlonchamp.id,
|
||||
items: [
|
||||
{
|
||||
reservation: {
|
||||
reservable_id: machine.id,
|
||||
reservable_type: machine.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}.to_json, headers: default_headers
|
||||
|
||||
# general assertions
|
||||
assert_equal 201, response.status
|
||||
assert_equal reservations_count + 1, Reservation.count
|
||||
assert_equal invoice_count + 1, Invoice.count
|
||||
assert_equal invoice_items_count + 1, InvoiceItem.count
|
||||
assert_equal users_credit_count, UsersCredit.count
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 0, @vlonchamp.subscriptions.count
|
||||
assert_nil @vlonchamp.subscribed_plan
|
||||
|
||||
# reservation assertions
|
||||
reservation = Reservation.last
|
||||
|
||||
assert reservation.original_invoice
|
||||
assert_equal 1, reservation.original_invoice.invoice_items.count
|
||||
|
||||
# invoice assertions
|
||||
invoice = reservation.original_invoice
|
||||
|
||||
assert invoice.payment_gateway_object.blank?
|
||||
assert_not invoice.total.blank?
|
||||
|
||||
# invoice_items assertions
|
||||
invoice_item = InvoiceItem.last
|
||||
|
||||
assert_equal machine.prices.find_by(group_id: @vlonchamp.group_id, plan_id: nil).amount, invoice_item.amount
|
||||
|
||||
# invoice assertions
|
||||
item = InvoiceItem.find_by(object: reservation)
|
||||
invoice = item.invoice
|
||||
assert_invoice_pdf invoice
|
||||
assert_not_nil invoice.debug_footprint
|
||||
|
||||
# notification
|
||||
assert_not_empty Notification.where(attached_object: reservation)
|
||||
|
||||
# wallet
|
||||
assert_equal @vlonchamp.wallet.amount, 0
|
||||
assert_equal @vlonchamp.wallet.wallet_transactions.count, 2
|
||||
transaction = @vlonchamp.wallet.wallet_transactions.last
|
||||
assert_equal transaction.transaction_type, 'debit'
|
||||
assert_equal transaction.amount, 10
|
||||
assert_equal transaction.amount, invoice.wallet_amount / 100.0
|
||||
assert_equal transaction.id, invoice.wallet_transaction_id
|
||||
end
|
||||
end
|
@ -271,7 +271,7 @@ class Reservations::PayWithWalletTest < ActionDispatch::IntegrationTest
|
||||
# Check the answer
|
||||
result = json_response(response.body)
|
||||
assert_equal payment_schedule.id, result[:id], 'payment schedule id does not match'
|
||||
subscription = payment_schedule.payment_schedule_objects.find { |pso| pso.object_type == Subscription.name }.object
|
||||
assert_equal plan.id, subscription.plan_id, 'subscribed plan does not match'
|
||||
subscription = payment_schedule.payment_schedule_objects.find { |pso| pso.object_type == Subscription.name }&.object
|
||||
assert_equal plan.id, subscription&.plan_id, 'subscribed plan does not match'
|
||||
end
|
||||
end
|
||||
|
96
test/integration/reservations/payment_schedule_test.rb
Normal file
96
test/integration/reservations/payment_schedule_test.rb
Normal file
@ -0,0 +1,96 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
module Reservations; end
|
||||
|
||||
class Reservations::PaymentScheduleTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user_without_subscription = User.members.without_subscription.first
|
||||
@admin = User.with_role(:admin).first
|
||||
login_as(@admin, scope: :user)
|
||||
end
|
||||
|
||||
test 'user reserves a training and a subscription with payment schedule' do
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
subscriptions_count = Subscription.count
|
||||
users_credit_count = UsersCredit.count
|
||||
payment_schedule_count = PaymentSchedule.count
|
||||
payment_schedule_items_count = PaymentScheduleItem.count
|
||||
|
||||
training = Training.find(1)
|
||||
availability = training.availabilities.first
|
||||
plan = Plan.find_by(group_id: @user_without_subscription.group.id, type: 'Plan', base_name: 'Abonnement mensualisable')
|
||||
|
||||
VCR.use_cassette('reservations_admin_training_subscription_with_payment_schedule') do
|
||||
post '/api/local_payment/confirm_payment', params: {
|
||||
payment_method: 'check',
|
||||
payment_schedule: true,
|
||||
customer_id: @user_without_subscription.id,
|
||||
items: [
|
||||
{
|
||||
reservation: {
|
||||
reservable_id: training.id,
|
||||
reservable_type: training.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
subscription: {
|
||||
plan_id: plan.id
|
||||
}
|
||||
}
|
||||
]
|
||||
}.to_json, headers: default_headers
|
||||
end
|
||||
|
||||
# get the objects
|
||||
reservation = Reservation.last
|
||||
payment_schedule = PaymentSchedule.last
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 201, response.status, response.body
|
||||
assert_equal Mime[:json], response.content_type
|
||||
assert_equal reservations_count + 1, Reservation.count, 'missing the reservation'
|
||||
assert_equal invoice_count, Invoice.count, "an invoice was generated but it shouldn't"
|
||||
assert_equal invoice_items_count, InvoiceItem.count, "some invoice items were generated but they shouldn't"
|
||||
assert_equal users_credit_count, UsersCredit.count, "user's credits count has changed but it shouldn't"
|
||||
assert_equal subscriptions_count + 1, Subscription.count, 'missing the subscription'
|
||||
assert_equal payment_schedule_count + 1, PaymentSchedule.count, 'missing the payment schedule'
|
||||
assert_equal payment_schedule_items_count + 12, PaymentScheduleItem.count, 'missing some payment schedule items'
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 1, @user_without_subscription.subscriptions.count
|
||||
assert_not_nil @user_without_subscription.subscribed_plan, "user's subscribed plan was not found"
|
||||
assert_not_nil @user_without_subscription.subscription, "user's subscription was not found"
|
||||
assert_equal plan.id, @user_without_subscription.subscribed_plan.id, "user's plan does not match"
|
||||
|
||||
# payment schedule assertions
|
||||
assert reservation.original_payment_schedule
|
||||
assert_equal payment_schedule.id, reservation.original_payment_schedule.id
|
||||
assert_not_nil payment_schedule.reference
|
||||
assert_equal 'check', payment_schedule.payment_method
|
||||
assert_empty payment_schedule.payment_gateway_objects
|
||||
assert_nil payment_schedule.wallet_transaction
|
||||
assert_nil payment_schedule.wallet_amount
|
||||
assert_nil payment_schedule.coupon_id
|
||||
assert_equal 'test', payment_schedule.environment
|
||||
assert payment_schedule.check_footprint
|
||||
assert_equal @user_without_subscription.invoicing_profile.id, payment_schedule.invoicing_profile_id
|
||||
assert_equal @admin.invoicing_profile.id, payment_schedule.operator_profile_id
|
||||
|
||||
# Check the answer
|
||||
result = json_response(response.body)
|
||||
assert_equal reservation.original_payment_schedule.id, result[:id], 'payment schedule id does not match'
|
||||
|
||||
# reservation assertions
|
||||
assert_equal result[:main_object][:id], reservation.id
|
||||
assert_equal payment_schedule.main_object.object, reservation
|
||||
end
|
||||
end
|
121
test/integration/reservations/privileged_user_test.rb
Normal file
121
test/integration/reservations/privileged_user_test.rb
Normal file
@ -0,0 +1,121 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
module Reservations; end
|
||||
|
||||
class Reservations::PrivilegedUserTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@admin = User.with_role(:admin).first
|
||||
login_as(@admin, scope: :user)
|
||||
end
|
||||
|
||||
test 'admin cannot reserves for himself with local payment' do
|
||||
machine = Machine.find(6)
|
||||
availability = machine.availabilities.first
|
||||
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
users_credit_count = UsersCredit.count
|
||||
|
||||
post '/api/local_payment/confirm_payment', params: {
|
||||
customer_id: @admin.id,
|
||||
items: [
|
||||
{
|
||||
reservation: {
|
||||
reservable_id: machine.id,
|
||||
reservable_type: machine.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}.to_json, headers: default_headers
|
||||
|
||||
# general assertions
|
||||
assert_equal 403, response.status
|
||||
assert_equal reservations_count, Reservation.count
|
||||
assert_equal invoice_count, Invoice.count
|
||||
assert_equal invoice_items_count, InvoiceItem.count
|
||||
assert_equal users_credit_count, UsersCredit.count
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 0, @admin.subscriptions.count
|
||||
assert_nil @admin.subscribed_plan
|
||||
end
|
||||
|
||||
test 'admin reserves a machine for himself with success' do
|
||||
machine = Machine.find(6)
|
||||
availability = machine.availabilities.first
|
||||
|
||||
reservations_count = Reservation.count
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
users_credit_count = UsersCredit.count
|
||||
subscriptions_count = Subscription.count
|
||||
|
||||
VCR.use_cassette('reservations_create_for_machine_as_admin_for_himself_success') do
|
||||
post '/api/stripe/confirm_payment',
|
||||
params: {
|
||||
payment_method_id: stripe_payment_method,
|
||||
cart_items: {
|
||||
customer_id: @admin.id,
|
||||
items: [
|
||||
{
|
||||
reservation: {
|
||||
reservable_id: machine.id,
|
||||
reservable_type: machine.class.name,
|
||||
slots_reservations_attributes: [
|
||||
{
|
||||
slot_id: availability.slots.first.id
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}.to_json, headers: default_headers
|
||||
end
|
||||
|
||||
# general assertions
|
||||
assert_equal 201, response.status
|
||||
assert_equal reservations_count + 1, Reservation.count
|
||||
assert_equal invoice_count + 1, Invoice.count
|
||||
assert_equal invoice_items_count + 1, InvoiceItem.count
|
||||
assert_equal users_credit_count, UsersCredit.count
|
||||
assert_equal subscriptions_count, Subscription.count
|
||||
|
||||
# subscription assertions
|
||||
assert_equal 0, @admin.subscriptions.count
|
||||
assert_nil @admin.subscribed_plan
|
||||
|
||||
# reservation assertions
|
||||
reservation = Reservation.last
|
||||
|
||||
assert reservation.original_invoice
|
||||
assert_equal 1, reservation.original_invoice.invoice_items.count
|
||||
|
||||
# invoice_items assertions
|
||||
invoice_item = InvoiceItem.last
|
||||
|
||||
assert_equal machine.prices.find_by(group_id: @admin.group_id, plan_id: nil).amount, invoice_item.amount
|
||||
assert invoice_item.check_footprint
|
||||
|
||||
# invoice assertions
|
||||
item = InvoiceItem.find_by(object: reservation)
|
||||
invoice = item.invoice
|
||||
assert_invoice_pdf invoice
|
||||
assert_not_nil invoice.debug_footprint
|
||||
|
||||
assert_not invoice.payment_gateway_object.blank?
|
||||
assert_not invoice.total.blank?
|
||||
assert invoice.check_footprint
|
||||
|
||||
# notification
|
||||
assert_not_empty Notification.where(attached_object: reservation)
|
||||
end
|
||||
end
|
@ -0,0 +1,560 @@
|
||||
---
|
||||
http_interactions:
|
||||
- request:
|
||||
method: post
|
||||
uri: https://api.stripe.com/v1/payment_methods
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: type=card&card[number]=4242424242424242&card[exp_month]=4&card[exp_year]=2023&card[cvc]=314
|
||||
headers:
|
||||
User-Agent:
|
||||
- Stripe/v1 RubyBindings/5.29.0
|
||||
Authorization:
|
||||
- Bearer sk_test_testfaketestfaketestfake
|
||||
Content-Type:
|
||||
- application/x-www-form-urlencoded
|
||||
Stripe-Version:
|
||||
- '2019-08-14'
|
||||
X-Stripe-Client-User-Agent:
|
||||
- '{"bindings_version":"5.29.0","lang":"ruby","lang_version":"2.6.10 p210 (2022-04-12)","platform":"x86_64-linux","engine":"ruby","publisher":"stripe","uname":"Linux
|
||||
version 6.0.2-arch1-1 (linux@archlinux) (gcc (GCC) 12.2.0, GNU ld (GNU Binutils)
|
||||
2.39.0) #1 SMP PREEMPT_DYNAMIC Sat, 15 Oct 2022 14:00:49 +0000","hostname":"Sylvain-desktop"}'
|
||||
Accept-Encoding:
|
||||
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
||||
Accept:
|
||||
- "*/*"
|
||||
response:
|
||||
status:
|
||||
code: 200
|
||||
message: OK
|
||||
headers:
|
||||
Server:
|
||||
- nginx
|
||||
Date:
|
||||
- Tue, 25 Oct 2022 12:24:00 GMT
|
||||
Content-Type:
|
||||
- application/json
|
||||
Content-Length:
|
||||
- '930'
|
||||
Connection:
|
||||
- keep-alive
|
||||
Access-Control-Allow-Credentials:
|
||||
- 'true'
|
||||
Access-Control-Allow-Methods:
|
||||
- GET, POST, HEAD, OPTIONS, DELETE
|
||||
Access-Control-Allow-Origin:
|
||||
- "*"
|
||||
Access-Control-Expose-Headers:
|
||||
- Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
|
||||
Access-Control-Max-Age:
|
||||
- '300'
|
||||
Cache-Control:
|
||||
- no-cache, no-store
|
||||
Idempotency-Key:
|
||||
- d2caa6d5-17aa-492b-92c9-a674cdf166bf
|
||||
Original-Request:
|
||||
- req_IyjaBwMZQGEkLi
|
||||
Request-Id:
|
||||
- req_IyjaBwMZQGEkLi
|
||||
Stripe-Should-Retry:
|
||||
- 'false'
|
||||
Stripe-Version:
|
||||
- '2019-08-14'
|
||||
Strict-Transport-Security:
|
||||
- max-age=63072000; includeSubDomains; preload
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: |-
|
||||
{
|
||||
"id": "pm_1LwmAm2sOmf47Nz9J3oTpRmL",
|
||||
"object": "payment_method",
|
||||
"billing_details": {
|
||||
"address": {
|
||||
"city": null,
|
||||
"country": null,
|
||||
"line1": null,
|
||||
"line2": null,
|
||||
"postal_code": null,
|
||||
"state": null
|
||||
},
|
||||
"email": null,
|
||||
"name": null,
|
||||
"phone": null
|
||||
},
|
||||
"card": {
|
||||
"brand": "visa",
|
||||
"checks": {
|
||||
"address_line1_check": null,
|
||||
"address_postal_code_check": null,
|
||||
"cvc_check": "unchecked"
|
||||
},
|
||||
"country": "US",
|
||||
"exp_month": 4,
|
||||
"exp_year": 2023,
|
||||
"fingerprint": "o52jybR7bnmNn6AT",
|
||||
"funding": "credit",
|
||||
"generated_from": null,
|
||||
"last4": "4242",
|
||||
"networks": {
|
||||
"available": [
|
||||
"visa"
|
||||
],
|
||||
"preferred": null
|
||||
},
|
||||
"three_d_secure_usage": {
|
||||
"supported": true
|
||||
},
|
||||
"wallet": null
|
||||
},
|
||||
"created": 1666700640,
|
||||
"customer": null,
|
||||
"livemode": false,
|
||||
"metadata": {},
|
||||
"type": "card"
|
||||
}
|
||||
recorded_at: Tue, 25 Oct 2022 12:24:00 GMT
|
||||
- request:
|
||||
method: post
|
||||
uri: https://api.stripe.com/v1/payment_intents
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: payment_method=pm_1LwmAm2sOmf47Nz9J3oTpRmL&amount=3200¤cy=usd&confirmation_method=manual&confirm=true&customer=cus_8CyNk3UTi8lvCc
|
||||
headers:
|
||||
User-Agent:
|
||||
- Stripe/v1 RubyBindings/5.29.0
|
||||
Authorization:
|
||||
- Bearer sk_test_testfaketestfaketestfake
|
||||
Content-Type:
|
||||
- application/x-www-form-urlencoded
|
||||
X-Stripe-Client-Telemetry:
|
||||
- '{"last_request_metrics":{"request_id":"req_IyjaBwMZQGEkLi","request_duration_ms":676}}'
|
||||
Stripe-Version:
|
||||
- '2019-08-14'
|
||||
X-Stripe-Client-User-Agent:
|
||||
- '{"bindings_version":"5.29.0","lang":"ruby","lang_version":"2.6.10 p210 (2022-04-12)","platform":"x86_64-linux","engine":"ruby","publisher":"stripe","uname":"Linux
|
||||
version 6.0.2-arch1-1 (linux@archlinux) (gcc (GCC) 12.2.0, GNU ld (GNU Binutils)
|
||||
2.39.0) #1 SMP PREEMPT_DYNAMIC Sat, 15 Oct 2022 14:00:49 +0000","hostname":"Sylvain-desktop"}'
|
||||
Accept-Encoding:
|
||||
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
||||
Accept:
|
||||
- "*/*"
|
||||
response:
|
||||
status:
|
||||
code: 200
|
||||
message: OK
|
||||
headers:
|
||||
Server:
|
||||
- nginx
|
||||
Date:
|
||||
- Tue, 25 Oct 2022 12:24:02 GMT
|
||||
Content-Type:
|
||||
- application/json
|
||||
Content-Length:
|
||||
- '4467'
|
||||
Connection:
|
||||
- keep-alive
|
||||
Access-Control-Allow-Credentials:
|
||||
- 'true'
|
||||
Access-Control-Allow-Methods:
|
||||
- GET, POST, HEAD, OPTIONS, DELETE
|
||||
Access-Control-Allow-Origin:
|
||||
- "*"
|
||||
Access-Control-Expose-Headers:
|
||||
- Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
|
||||
Access-Control-Max-Age:
|
||||
- '300'
|
||||
Cache-Control:
|
||||
- no-cache, no-store
|
||||
Idempotency-Key:
|
||||
- 36cf63a0-1991-46f2-b878-e57be73a8d20
|
||||
Original-Request:
|
||||
- req_9igfE4GGSynHxB
|
||||
Request-Id:
|
||||
- req_9igfE4GGSynHxB
|
||||
Stripe-Should-Retry:
|
||||
- 'false'
|
||||
Stripe-Version:
|
||||
- '2019-08-14'
|
||||
Strict-Transport-Security:
|
||||
- max-age=63072000; includeSubDomains; preload
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: |-
|
||||
{
|
||||
"id": "pi_3LwmAn2sOmf47Nz91stZM07n",
|
||||
"object": "payment_intent",
|
||||
"amount": 3200,
|
||||
"amount_capturable": 0,
|
||||
"amount_details": {
|
||||
"tip": {}
|
||||
},
|
||||
"amount_received": 3200,
|
||||
"application": null,
|
||||
"application_fee_amount": null,
|
||||
"automatic_payment_methods": null,
|
||||
"canceled_at": null,
|
||||
"cancellation_reason": null,
|
||||
"capture_method": "automatic",
|
||||
"charges": {
|
||||
"object": "list",
|
||||
"data": [
|
||||
{
|
||||
"id": "ch_3LwmAn2sOmf47Nz91lGaYKm6",
|
||||
"object": "charge",
|
||||
"amount": 3200,
|
||||
"amount_captured": 3200,
|
||||
"amount_refunded": 0,
|
||||
"application": null,
|
||||
"application_fee": null,
|
||||
"application_fee_amount": null,
|
||||
"balance_transaction": "txn_3LwmAn2sOmf47Nz91eAundgZ",
|
||||
"billing_details": {
|
||||
"address": {
|
||||
"city": null,
|
||||
"country": null,
|
||||
"line1": null,
|
||||
"line2": null,
|
||||
"postal_code": null,
|
||||
"state": null
|
||||
},
|
||||
"email": null,
|
||||
"name": null,
|
||||
"phone": null
|
||||
},
|
||||
"calculated_statement_descriptor": "Stripe",
|
||||
"captured": true,
|
||||
"created": 1666700641,
|
||||
"currency": "usd",
|
||||
"customer": "cus_8CyNk3UTi8lvCc",
|
||||
"description": null,
|
||||
"destination": null,
|
||||
"dispute": null,
|
||||
"disputed": false,
|
||||
"failure_balance_transaction": null,
|
||||
"failure_code": null,
|
||||
"failure_message": null,
|
||||
"fraud_details": {},
|
||||
"invoice": null,
|
||||
"livemode": false,
|
||||
"metadata": {},
|
||||
"on_behalf_of": null,
|
||||
"order": null,
|
||||
"outcome": {
|
||||
"network_status": "approved_by_network",
|
||||
"reason": null,
|
||||
"risk_level": "normal",
|
||||
"risk_score": 6,
|
||||
"seller_message": "Payment complete.",
|
||||
"type": "authorized"
|
||||
},
|
||||
"paid": true,
|
||||
"payment_intent": "pi_3LwmAn2sOmf47Nz91stZM07n",
|
||||
"payment_method": "pm_1LwmAm2sOmf47Nz9J3oTpRmL",
|
||||
"payment_method_details": {
|
||||
"card": {
|
||||
"brand": "visa",
|
||||
"checks": {
|
||||
"address_line1_check": null,
|
||||
"address_postal_code_check": null,
|
||||
"cvc_check": "pass"
|
||||
},
|
||||
"country": "US",
|
||||
"exp_month": 4,
|
||||
"exp_year": 2023,
|
||||
"fingerprint": "o52jybR7bnmNn6AT",
|
||||
"funding": "credit",
|
||||
"installments": null,
|
||||
"last4": "4242",
|
||||
"mandate": null,
|
||||
"network": "visa",
|
||||
"three_d_secure": null,
|
||||
"wallet": null
|
||||
},
|
||||
"type": "card"
|
||||
},
|
||||
"receipt_email": null,
|
||||
"receipt_number": null,
|
||||
"receipt_url": "https://pay.stripe.com/receipts/payment/CAcaFwoVYWNjdF8xMDNyRTYyc09tZjQ3Tno5KOKq35oGMgbxVBhdgwo6LBaPqJIeyW4O5X-cvbYdENfEYHKFIXhtA-WRqLqkwoqCJh37CjVAqDerZ6Ny",
|
||||
"refunded": false,
|
||||
"refunds": {
|
||||
"object": "list",
|
||||
"data": [],
|
||||
"has_more": false,
|
||||
"total_count": 0,
|
||||
"url": "/v1/charges/ch_3LwmAn2sOmf47Nz91lGaYKm6/refunds"
|
||||
},
|
||||
"review": null,
|
||||
"shipping": null,
|
||||
"source": null,
|
||||
"source_transfer": null,
|
||||
"statement_descriptor": null,
|
||||
"statement_descriptor_suffix": null,
|
||||
"status": "succeeded",
|
||||
"transfer_data": null,
|
||||
"transfer_group": null
|
||||
}
|
||||
],
|
||||
"has_more": false,
|
||||
"total_count": 1,
|
||||
"url": "/v1/charges?payment_intent=pi_3LwmAn2sOmf47Nz91stZM07n"
|
||||
},
|
||||
"client_secret": "pi_3LwmAn2sOmf47Nz91stZM07n_secret_senD8pGcSSa6gwoY1dGU87TUy",
|
||||
"confirmation_method": "manual",
|
||||
"created": 1666700641,
|
||||
"currency": "usd",
|
||||
"customer": "cus_8CyNk3UTi8lvCc",
|
||||
"description": null,
|
||||
"invoice": null,
|
||||
"last_payment_error": null,
|
||||
"livemode": false,
|
||||
"metadata": {},
|
||||
"next_action": null,
|
||||
"on_behalf_of": null,
|
||||
"payment_method": "pm_1LwmAm2sOmf47Nz9J3oTpRmL",
|
||||
"payment_method_options": {
|
||||
"card": {
|
||||
"installments": null,
|
||||
"mandate_options": null,
|
||||
"network": null,
|
||||
"request_three_d_secure": "automatic"
|
||||
}
|
||||
},
|
||||
"payment_method_types": [
|
||||
"card"
|
||||
],
|
||||
"processing": null,
|
||||
"receipt_email": null,
|
||||
"review": null,
|
||||
"setup_future_usage": null,
|
||||
"shipping": null,
|
||||
"source": null,
|
||||
"statement_descriptor": null,
|
||||
"statement_descriptor_suffix": null,
|
||||
"status": "succeeded",
|
||||
"transfer_data": null,
|
||||
"transfer_group": null
|
||||
}
|
||||
recorded_at: Tue, 25 Oct 2022 12:24:02 GMT
|
||||
- request:
|
||||
method: post
|
||||
uri: https://api.stripe.com/v1/payment_intents/pi_3LwmAn2sOmf47Nz91stZM07n
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: description=Invoice+reference%3A+2210001
|
||||
headers:
|
||||
User-Agent:
|
||||
- Stripe/v1 RubyBindings/5.29.0
|
||||
Authorization:
|
||||
- Bearer sk_test_testfaketestfaketestfake
|
||||
Content-Type:
|
||||
- application/x-www-form-urlencoded
|
||||
X-Stripe-Client-Telemetry:
|
||||
- '{"last_request_metrics":{"request_id":"req_9igfE4GGSynHxB","request_duration_ms":1804}}'
|
||||
Stripe-Version:
|
||||
- '2019-08-14'
|
||||
X-Stripe-Client-User-Agent:
|
||||
- '{"bindings_version":"5.29.0","lang":"ruby","lang_version":"2.6.10 p210 (2022-04-12)","platform":"x86_64-linux","engine":"ruby","publisher":"stripe","uname":"Linux
|
||||
version 6.0.2-arch1-1 (linux@archlinux) (gcc (GCC) 12.2.0, GNU ld (GNU Binutils)
|
||||
2.39.0) #1 SMP PREEMPT_DYNAMIC Sat, 15 Oct 2022 14:00:49 +0000","hostname":"Sylvain-desktop"}'
|
||||
Accept-Encoding:
|
||||
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
||||
Accept:
|
||||
- "*/*"
|
||||
response:
|
||||
status:
|
||||
code: 200
|
||||
message: OK
|
||||
headers:
|
||||
Server:
|
||||
- nginx
|
||||
Date:
|
||||
- Tue, 25 Oct 2022 12:24:03 GMT
|
||||
Content-Type:
|
||||
- application/json
|
||||
Content-Length:
|
||||
- '4491'
|
||||
Connection:
|
||||
- keep-alive
|
||||
Access-Control-Allow-Credentials:
|
||||
- 'true'
|
||||
Access-Control-Allow-Methods:
|
||||
- GET, POST, HEAD, OPTIONS, DELETE
|
||||
Access-Control-Allow-Origin:
|
||||
- "*"
|
||||
Access-Control-Expose-Headers:
|
||||
- Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
|
||||
Access-Control-Max-Age:
|
||||
- '300'
|
||||
Cache-Control:
|
||||
- no-cache, no-store
|
||||
Idempotency-Key:
|
||||
- 4922e47c-d879-40e3-9fe8-03d31aae42fc
|
||||
Original-Request:
|
||||
- req_t3nUSQYBoywCRu
|
||||
Request-Id:
|
||||
- req_t3nUSQYBoywCRu
|
||||
Stripe-Should-Retry:
|
||||
- 'false'
|
||||
Stripe-Version:
|
||||
- '2019-08-14'
|
||||
Strict-Transport-Security:
|
||||
- max-age=63072000; includeSubDomains; preload
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: |-
|
||||
{
|
||||
"id": "pi_3LwmAn2sOmf47Nz91stZM07n",
|
||||
"object": "payment_intent",
|
||||
"amount": 3200,
|
||||
"amount_capturable": 0,
|
||||
"amount_details": {
|
||||
"tip": {}
|
||||
},
|
||||
"amount_received": 3200,
|
||||
"application": null,
|
||||
"application_fee_amount": null,
|
||||
"automatic_payment_methods": null,
|
||||
"canceled_at": null,
|
||||
"cancellation_reason": null,
|
||||
"capture_method": "automatic",
|
||||
"charges": {
|
||||
"object": "list",
|
||||
"data": [
|
||||
{
|
||||
"id": "ch_3LwmAn2sOmf47Nz91lGaYKm6",
|
||||
"object": "charge",
|
||||
"amount": 3200,
|
||||
"amount_captured": 3200,
|
||||
"amount_refunded": 0,
|
||||
"application": null,
|
||||
"application_fee": null,
|
||||
"application_fee_amount": null,
|
||||
"balance_transaction": "txn_3LwmAn2sOmf47Nz91eAundgZ",
|
||||
"billing_details": {
|
||||
"address": {
|
||||
"city": null,
|
||||
"country": null,
|
||||
"line1": null,
|
||||
"line2": null,
|
||||
"postal_code": null,
|
||||
"state": null
|
||||
},
|
||||
"email": null,
|
||||
"name": null,
|
||||
"phone": null
|
||||
},
|
||||
"calculated_statement_descriptor": "Stripe",
|
||||
"captured": true,
|
||||
"created": 1666700641,
|
||||
"currency": "usd",
|
||||
"customer": "cus_8CyNk3UTi8lvCc",
|
||||
"description": null,
|
||||
"destination": null,
|
||||
"dispute": null,
|
||||
"disputed": false,
|
||||
"failure_balance_transaction": null,
|
||||
"failure_code": null,
|
||||
"failure_message": null,
|
||||
"fraud_details": {},
|
||||
"invoice": null,
|
||||
"livemode": false,
|
||||
"metadata": {},
|
||||
"on_behalf_of": null,
|
||||
"order": null,
|
||||
"outcome": {
|
||||
"network_status": "approved_by_network",
|
||||
"reason": null,
|
||||
"risk_level": "normal",
|
||||
"risk_score": 6,
|
||||
"seller_message": "Payment complete.",
|
||||
"type": "authorized"
|
||||
},
|
||||
"paid": true,
|
||||
"payment_intent": "pi_3LwmAn2sOmf47Nz91stZM07n",
|
||||
"payment_method": "pm_1LwmAm2sOmf47Nz9J3oTpRmL",
|
||||
"payment_method_details": {
|
||||
"card": {
|
||||
"brand": "visa",
|
||||
"checks": {
|
||||
"address_line1_check": null,
|
||||
"address_postal_code_check": null,
|
||||
"cvc_check": "pass"
|
||||
},
|
||||
"country": "US",
|
||||
"exp_month": 4,
|
||||
"exp_year": 2023,
|
||||
"fingerprint": "o52jybR7bnmNn6AT",
|
||||
"funding": "credit",
|
||||
"installments": null,
|
||||
"last4": "4242",
|
||||
"mandate": null,
|
||||
"network": "visa",
|
||||
"three_d_secure": null,
|
||||
"wallet": null
|
||||
},
|
||||
"type": "card"
|
||||
},
|
||||
"receipt_email": null,
|
||||
"receipt_number": null,
|
||||
"receipt_url": "https://pay.stripe.com/receipts/payment/CAcaFwoVYWNjdF8xMDNyRTYyc09tZjQ3Tno5KOOq35oGMgYTK7s3Lw06LBbw-9lgITJWB30pZngrYDHYjDJ0XFWVlXrbaaqPhzCBYn5QQ1aQPnDFheEh",
|
||||
"refunded": false,
|
||||
"refunds": {
|
||||
"object": "list",
|
||||
"data": [],
|
||||
"has_more": false,
|
||||
"total_count": 0,
|
||||
"url": "/v1/charges/ch_3LwmAn2sOmf47Nz91lGaYKm6/refunds"
|
||||
},
|
||||
"review": null,
|
||||
"shipping": null,
|
||||
"source": null,
|
||||
"source_transfer": null,
|
||||
"statement_descriptor": null,
|
||||
"statement_descriptor_suffix": null,
|
||||
"status": "succeeded",
|
||||
"transfer_data": null,
|
||||
"transfer_group": null
|
||||
}
|
||||
],
|
||||
"has_more": false,
|
||||
"total_count": 1,
|
||||
"url": "/v1/charges?payment_intent=pi_3LwmAn2sOmf47Nz91stZM07n"
|
||||
},
|
||||
"client_secret": "pi_3LwmAn2sOmf47Nz91stZM07n_secret_senD8pGcSSa6gwoY1dGU87TUy",
|
||||
"confirmation_method": "manual",
|
||||
"created": 1666700641,
|
||||
"currency": "usd",
|
||||
"customer": "cus_8CyNk3UTi8lvCc",
|
||||
"description": "Invoice reference: 2210001",
|
||||
"invoice": null,
|
||||
"last_payment_error": null,
|
||||
"livemode": false,
|
||||
"metadata": {},
|
||||
"next_action": null,
|
||||
"on_behalf_of": null,
|
||||
"payment_method": "pm_1LwmAm2sOmf47Nz9J3oTpRmL",
|
||||
"payment_method_options": {
|
||||
"card": {
|
||||
"installments": null,
|
||||
"mandate_options": null,
|
||||
"network": null,
|
||||
"request_three_d_secure": "automatic"
|
||||
}
|
||||
},
|
||||
"payment_method_types": [
|
||||
"card"
|
||||
],
|
||||
"processing": null,
|
||||
"receipt_email": null,
|
||||
"review": null,
|
||||
"setup_future_usage": null,
|
||||
"shipping": null,
|
||||
"source": null,
|
||||
"statement_descriptor": null,
|
||||
"statement_descriptor_suffix": null,
|
||||
"status": "succeeded",
|
||||
"transfer_data": null,
|
||||
"transfer_group": null
|
||||
}
|
||||
recorded_at: Tue, 25 Oct 2022 12:24:03 GMT
|
||||
recorded_with: VCR 6.0.0
|
Loading…
x
Reference in New Issue
Block a user