From c6ec062530561b1e3201e4d7faf51439eef99b59 Mon Sep 17 00:00:00 2001 From: Du Peng Date: Thu, 3 Nov 2022 10:41:19 +0100 Subject: [PATCH 1/4] (bug) update product sku translate --- config/locales/app.admin.en.yml | 2 +- config/locales/app.admin.fr.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index 6405deca6..c21dc1b64 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -2080,7 +2080,7 @@ en: clone_product: "Duplicate the product" clone: "Duplicate" name: "Name" - sku: "URL" + sku: "Product reference (SKU)" is_show_in_store: "Available in the store" active_price_info: "Is this product visible by the members on the store?" orders: diff --git a/config/locales/app.admin.fr.yml b/config/locales/app.admin.fr.yml index ac87b2407..c62c05c25 100644 --- a/config/locales/app.admin.fr.yml +++ b/config/locales/app.admin.fr.yml @@ -2080,7 +2080,7 @@ fr: clone_product: "Dupliquer le produit" clone: "Dupliquer" name: "Nom" - sku: "URL" + sku: "Référence du produit (SKU)" is_show_in_store: "Disponible dans la boutique" active_price_info: "Ce produit est-il visible par les membres dans la boutique ?" orders: From 42be9ae3e7ecb6c4339a4516cf8a5866b6791a53 Mon Sep 17 00:00:00 2001 From: Du Peng Date: Mon, 7 Nov 2022 16:04:53 +0100 Subject: [PATCH 2/4] (bug) fix cant set payment_method if admin pay a reservation himself in invoice --- app/services/invoices_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/invoices_service.rb b/app/services/invoices_service.rb index e85a5fe79..78dd1bcae 100644 --- a/app/services/invoices_service.rb +++ b/app/services/invoices_service.rb @@ -73,7 +73,7 @@ class InvoicesService method = if payment_method payment_method else - operator&.admin? || (operator&.manager? && operator != user) ? nil : 'card' + (operator&.admin? || operator&.manager?) && operator != user ? nil : 'card' end invoice = Invoice.new( From ac2de3d22e33f6b18a1ae8d8f2358aa8026fd515 Mon Sep 17 00:00:00 2001 From: Du Peng Date: Mon, 7 Nov 2022 18:51:49 +0100 Subject: [PATCH 3/4] (bug) admin cannot pay order by card --- app/services/checkout/payment_service.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/services/checkout/payment_service.rb b/app/services/checkout/payment_service.rb index 4dcbc218d..f84535f3b 100644 --- a/app/services/checkout/payment_service.rb +++ b/app/services/checkout/payment_service.rb @@ -18,16 +18,14 @@ class Checkout::PaymentService CouponService.new.validate(coupon_code, order.statistic_profile.user.id) amount = debit_amount(order) - if operator.privileged? || amount.zero? + if (operator.privileged? && operator != order.statistic_profile.user) || amount.zero? Payments::LocalService.new.payment(order, coupon_code) - elsif operator.member? - if Stripe::Helper.enabled? - Payments::StripeService.new.payment(order, coupon_code, payment_id) - elsif PayZen::Helper.enabled? - Payments::PayzenService.new.payment(order, coupon_code) - else - raise Error('Bad gateway or online payment is disabled') - end + elsif Stripe::Helper.enabled? && payment_id.present? + Payments::StripeService.new.payment(order, coupon_code, payment_id) + elsif PayZen::Helper.enabled? + Payments::PayzenService.new.payment(order, coupon_code) + else + raise Error('Bad gateway or online payment is disabled') end end From 46ef0170b9858a5d9ec3d5ee3be0e853c0ac0a88 Mon Sep 17 00:00:00 2001 From: Du Peng Date: Mon, 7 Nov 2022 18:52:43 +0100 Subject: [PATCH 4/4] (test) add admin pay order test --- test/fixtures/order_items.yml | 10 + test/fixtures/orders.yml | 2 +- test/helpers/invoice_helper.rb | 2 +- .../integration/store/admin_pay_order_test.rb | 426 ++++++++++++++++++ test/integration/store/user_pay_order_test.rb | 65 ++- .../cart/find_or_create_service_test.rb | 2 +- test/services/cart/set_offer_service_test.rb | 6 +- ...r_admin_pay_by_cart_and_wallet_success.yml | 338 ++++++++++++++ .../store_order_admin_pay_by_cart_success.yml | 340 ++++++++++++++ ...e_order_pay_by_cart_and_wallet_success.yml | 338 ++++++++++++++ 10 files changed, 1521 insertions(+), 8 deletions(-) create mode 100644 test/integration/store/admin_pay_order_test.rb create mode 100644 test/vcr_cassettes/store_order_admin_pay_by_cart_and_wallet_success.yml create mode 100644 test/vcr_cassettes/store_order_admin_pay_by_cart_success.yml create mode 100644 test/vcr_cassettes/store_order_pay_by_cart_and_wallet_success.yml diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml index 68d0a0187..10d1da467 100644 --- a/test/fixtures/order_items.yml +++ b/test/fixtures/order_items.yml @@ -158,3 +158,13 @@ order_item_27: is_offered: created_at: <%= DateTime.current.utc.change({:hour => 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %> updated_at: <%= DateTime.current.utc.change({:hour => 15}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %> +order_item_28: + id: 28 + order_id: 20 + orderable_type: Product + orderable_id: 13 + amount: 500 + quantity: 2 + is_offered: + created_at: <%= DateTime.current.utc.change({:hour => 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %> + updated_at: <%= DateTime.current.utc.change({:hour => 15}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %> diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml index 3d8a9de55..d52c00405 100644 --- a/test/fixtures/orders.yml +++ b/test/fixtures/orders.yml @@ -239,7 +239,7 @@ order_20: token: 0DKxbAOzSXRx-amXyhmDdg1666691976019 reference: '005904-<%= DateTime.current.utc.strftime('%m') %>-<%= DateTime.current.utc.strftime('%d') %>' state: cart - total: 261500 + total: 262500 created_at: <%= DateTime.current.utc.change({:hour => 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %> updated_at: <%= DateTime.current.utc.change({:hour => 15}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %> wallet_amount: diff --git a/test/helpers/invoice_helper.rb b/test/helpers/invoice_helper.rb index 0faba67e5..829f52c31 100644 --- a/test/helpers/invoice_helper.rb +++ b/test/helpers/invoice_helper.rb @@ -35,7 +35,7 @@ module InvoiceHelper # Line of text should be of form 'Label $10.00' # @returns {float} def parse_amount_from_invoice_line(line) - line[line.rindex(' ') + 1..].tr(I18n.t('number.currency.format.unit'), '').to_f + line[line.rindex(' ') + 1..].tr(I18n.t('number.currency.format.unit'), '').gsub(/[$,]/, '').to_f end # check VAT and total excluding taxes diff --git a/test/integration/store/admin_pay_order_test.rb b/test/integration/store/admin_pay_order_test.rb new file mode 100644 index 000000000..3b303f112 --- /dev/null +++ b/test/integration/store/admin_pay_order_test.rb @@ -0,0 +1,426 @@ +# frozen_string_literal: true + +require 'test_helper' + +module Store; end + +class Store::AdminPayOrderTest < ActionDispatch::IntegrationTest + setup do + @admin = User.find_by(username: 'admin') + @pjproudhon = User.find_by(username: 'pjproudhon') + @caisse_en_bois = Product.find_by(slug: 'caisse-en-bois') + @panneaux = Product.find_by(slug: 'panneaux-de-mdf') + @cart1 = Order.find_by(token: '0DKxbAOzSXRx-amXyhmDdg1666691976019') + end + + test 'admin pay himself order by cart with success' do + login_as(@admin, scope: :user) + + invoice_count = Invoice.count + invoice_items_count = InvoiceItem.count + + VCR.use_cassette('store_order_admin_pay_by_cart_success') do + post '/api/checkout/payment', + params: { + payment_id: stripe_payment_method, + order_token: @cart1.token, + customer_id: @admin.id + }.to_json, headers: default_headers + end + + @cart1.reload + + # general assertions + assert_equal 200, response.status + assert_equal invoice_count + 1, Invoice.count + assert_equal invoice_items_count + 2, InvoiceItem.count + + # invoice_items assertions + invoice_item = InvoiceItem.last + + assert invoice_item.check_footprint + + # invoice assertions + invoice = Invoice.last + assert_invoice_pdf invoice + assert_not_nil invoice.debug_footprint + + assert_not @cart1.payment_gateway_object.blank? + assert_not invoice.payment_gateway_object.blank? + assert_not invoice.total.blank? + assert invoice.check_footprint + + # notification + assert_not_empty Notification.where(attached_object: invoice) + + assert_equal @cart1.state, 'paid' + assert_equal @cart1.payment_method, 'card' + assert_equal @cart1.paid_total, 262_500 + + stock_movement = @caisse_en_bois.product_stock_movements.last + assert_equal stock_movement.stock_type, 'external' + assert_equal stock_movement.reason, 'sold' + assert_equal stock_movement.quantity, -5 + assert_equal stock_movement.order_item_id, @cart1.order_items.first.id + + stock_movement = @panneaux.product_stock_movements.last + assert_equal stock_movement.stock_type, 'external' + assert_equal stock_movement.reason, 'sold' + assert_equal stock_movement.quantity, -2 + assert_equal stock_movement.order_item_id, @cart1.order_items.last.id + + activity = @cart1.order_activities.last + assert_equal activity.activity_type, 'paid' + assert_equal activity.operator_profile_id, @admin.invoicing_profile.id + end + + test 'admin pay himself order by cart and wallet with success' do + login_as(@admin, scope: :user) + + service = WalletService.new(user: @admin, wallet: @admin.wallet) + service.credit(1000) + + invoice_count = Invoice.count + invoice_items_count = InvoiceItem.count + users_credit_count = UsersCredit.count + wallet_transactions_count = WalletTransaction.count + + VCR.use_cassette('store_order_admin_pay_by_cart_and_wallet_success') do + post '/api/checkout/payment', + params: { + payment_id: stripe_payment_method, + order_token: @cart1.token, + customer_id: @admin.id + }.to_json, headers: default_headers + end + + @admin.wallet.reload + @cart1.reload + + # general assertions + assert_equal 200, response.status + assert_equal invoice_count + 1, Invoice.count + assert_equal invoice_items_count + 2, InvoiceItem.count + + # invoice_items assertions + invoice_item = InvoiceItem.last + + assert invoice_item.check_footprint + + # invoice assertions + invoice = Invoice.last + assert_invoice_pdf invoice + assert_not_nil invoice.debug_footprint + + assert_not @cart1.payment_gateway_object.blank? + assert_not invoice.payment_gateway_object.blank? + assert_not invoice.total.blank? + assert invoice.check_footprint + + # notification + assert_not_empty Notification.where(attached_object: invoice) + + assert_equal @cart1.state, 'paid' + assert_equal @cart1.payment_method, 'card' + assert_equal @cart1.paid_total, 162_500 + assert_equal users_credit_count, UsersCredit.count + assert_equal wallet_transactions_count + 1, WalletTransaction.count + + # wallet + assert_equal 0, @admin.wallet.amount + assert_equal 2, @admin.wallet.wallet_transactions.count + transaction = @admin.wallet.wallet_transactions.last + assert_equal 'debit', transaction.transaction_type + assert_equal @cart1.wallet_amount / 100.0, transaction.amount + assert_equal @cart1.wallet_transaction_id, transaction.id + assert_equal invoice.wallet_amount / 100.0, transaction.amount + end + + test 'admin pay user order by local with success' do + login_as(@admin, scope: :user) + + invoice_count = Invoice.count + invoice_items_count = InvoiceItem.count + + post '/api/checkout/payment', + params: { + order_token: @cart1.token, + customer_id: @pjproudhon.id + }.to_json, headers: default_headers + + @cart1.reload + + # general assertions + assert_equal 200, response.status + assert_equal invoice_count + 1, Invoice.count + assert_equal invoice_items_count + 2, InvoiceItem.count + + # invoice_items assertions + invoice_item = InvoiceItem.last + + assert invoice_item.check_footprint + + # invoice assertions + invoice = Invoice.last + assert_invoice_pdf invoice + assert_not_nil invoice.debug_footprint + + assert @cart1.payment_gateway_object.blank? + assert invoice.payment_gateway_object.blank? + assert_not invoice.total.blank? + assert invoice.check_footprint + + # notification + assert_not_empty Notification.where(attached_object: invoice) + + assert_equal @cart1.state, 'paid' + assert_equal @cart1.payment_method, 'local' + assert_equal @cart1.paid_total, 262_500 + + stock_movement = @caisse_en_bois.product_stock_movements.last + assert_equal stock_movement.stock_type, 'external' + assert_equal stock_movement.reason, 'sold' + assert_equal stock_movement.quantity, -5 + assert_equal stock_movement.order_item_id, @cart1.order_items.first.id + + stock_movement = @panneaux.product_stock_movements.last + assert_equal stock_movement.stock_type, 'external' + assert_equal stock_movement.reason, 'sold' + assert_equal stock_movement.quantity, -2 + assert_equal stock_movement.order_item_id, @cart1.order_items.last.id + + activity = @cart1.order_activities.last + assert_equal activity.activity_type, 'paid' + assert_equal activity.operator_profile_id, @admin.invoicing_profile.id + end + + test 'admin pay user offered order by local with success' do + login_as(@admin, scope: :user) + + invoice_count = Invoice.count + invoice_items_count = InvoiceItem.count + + @cart1 = Cart::SetOfferService.new.call(@cart1, @caisse_en_bois, true) + + post '/api/checkout/payment', + params: { + order_token: @cart1.token, + customer_id: @pjproudhon.id + }.to_json, headers: default_headers + + @cart1.reload + + # general assertions + assert_equal 200, response.status + assert_equal invoice_count + 1, Invoice.count + assert_equal invoice_items_count + 2, InvoiceItem.count + + # invoice_items assertions + invoice_item = InvoiceItem.last + + assert invoice_item.check_footprint + + # invoice assertions + invoice = Invoice.last + assert_invoice_pdf invoice + assert_not_nil invoice.debug_footprint + + assert @cart1.payment_gateway_object.blank? + assert invoice.payment_gateway_object.blank? + assert_not invoice.total.blank? + assert invoice.check_footprint + + # notification + assert_not_empty Notification.where(attached_object: invoice) + + assert_equal @cart1.state, 'paid' + assert_equal @cart1.payment_method, 'local' + assert_equal @cart1.paid_total, 1_000 + + stock_movement = @caisse_en_bois.product_stock_movements.last + assert_equal stock_movement.stock_type, 'external' + assert_equal stock_movement.reason, 'sold' + assert_equal stock_movement.quantity, -5 + assert_equal stock_movement.order_item_id, @cart1.order_items.first.id + + stock_movement = @panneaux.product_stock_movements.last + assert_equal stock_movement.stock_type, 'external' + assert_equal stock_movement.reason, 'sold' + assert_equal stock_movement.quantity, -2 + assert_equal stock_movement.order_item_id, @cart1.order_items.last.id + + activity = @cart1.order_activities.last + assert_equal activity.activity_type, 'paid' + assert_equal activity.operator_profile_id, @admin.invoicing_profile.id + end + + test 'admin pay himself order by wallet with success' do + login_as(@admin, scope: :user) + + service = WalletService.new(user: @admin, wallet: @admin.wallet) + service.credit(@cart1.total / 100) + + invoice_count = Invoice.count + invoice_items_count = InvoiceItem.count + users_credit_count = UsersCredit.count + wallet_transactions_count = WalletTransaction.count + + post '/api/checkout/payment', + params: { + order_token: @cart1.token, + customer_id: @admin.id + }.to_json, headers: default_headers + + @admin.wallet.reload + @cart1.reload + + # general assertions + assert_equal 200, response.status + assert_equal @cart1.state, 'paid' + assert_equal invoice_count + 1, Invoice.count + assert_equal invoice_items_count + 2, InvoiceItem.count + assert_equal users_credit_count, UsersCredit.count + assert_equal wallet_transactions_count + 1, WalletTransaction.count + + # invoice_items assertions + invoice_item = InvoiceItem.last + + assert invoice_item.check_footprint + + # invoice assertions + invoice = Invoice.last + assert_invoice_pdf invoice + assert_not_nil invoice.debug_footprint + + assert invoice.payment_gateway_object.blank? + assert_not invoice.total.blank? + assert invoice.check_footprint + + # notification + assert_not_empty Notification.where(attached_object: invoice) + + # wallet + assert_equal 0, @admin.wallet.amount + assert_equal 2, @admin.wallet.wallet_transactions.count + transaction = @admin.wallet.wallet_transactions.last + assert_equal 'debit', transaction.transaction_type + assert_equal @cart1.paid_total, 0 + assert_equal @cart1.wallet_amount / 100.0, transaction.amount + assert_equal @cart1.payment_method, 'wallet' + assert_equal @cart1.wallet_transaction_id, transaction.id + assert_equal invoice.wallet_amount / 100.0, transaction.amount + end + + test 'admin pay user order by wallet with success' do + login_as(@admin, scope: :user) + + service = WalletService.new(user: @admin, wallet: @pjproudhon.wallet) + service.credit(@cart1.total / 100) + + invoice_count = Invoice.count + invoice_items_count = InvoiceItem.count + users_credit_count = UsersCredit.count + wallet_transactions_count = WalletTransaction.count + + post '/api/checkout/payment', + params: { + order_token: @cart1.token, + customer_id: @pjproudhon.id + }.to_json, headers: default_headers + + @pjproudhon.wallet.reload + @cart1.reload + + # general assertions + assert_equal 200, response.status + assert_equal @cart1.state, 'paid' + assert_equal invoice_count + 1, Invoice.count + assert_equal invoice_items_count + 2, InvoiceItem.count + assert_equal users_credit_count, UsersCredit.count + assert_equal wallet_transactions_count + 1, WalletTransaction.count + + # invoice_items assertions + invoice_item = InvoiceItem.last + + assert invoice_item.check_footprint + + # invoice assertions + invoice = Invoice.last + assert_invoice_pdf invoice + assert_not_nil invoice.debug_footprint + + assert invoice.payment_gateway_object.blank? + assert_not invoice.total.blank? + assert invoice.check_footprint + + # notification + assert_not_empty Notification.where(attached_object: invoice) + + # wallet + assert_equal 0, @pjproudhon.wallet.amount + assert_equal 2, @pjproudhon.wallet.wallet_transactions.count + transaction = @pjproudhon.wallet.wallet_transactions.last + assert_equal 'debit', transaction.transaction_type + assert_equal @cart1.paid_total, 0 + assert_equal @cart1.wallet_amount / 100.0, transaction.amount + assert_equal @cart1.payment_method, 'wallet' + assert_equal @cart1.wallet_transaction_id, transaction.id + assert_equal invoice.wallet_amount / 100.0, transaction.amount + end + + test 'admin pay user order by wallet and coupon with success' do + login_as(@admin, scope: :user) + + service = WalletService.new(user: @admin, wallet: @pjproudhon.wallet) + service.credit(@cart1.total / 100) + + invoice_count = Invoice.count + invoice_items_count = InvoiceItem.count + users_credit_count = UsersCredit.count + wallet_transactions_count = WalletTransaction.count + + post '/api/checkout/payment', + params: { + order_token: @cart1.token, + customer_id: @pjproudhon.id, + coupon_code: 'GIME3EUR' + }.to_json, headers: default_headers + + @pjproudhon.wallet.reload + @cart1.reload + + # general assertions + assert_equal 200, response.status + assert_equal @cart1.state, 'paid' + assert_equal invoice_count + 1, Invoice.count + assert_equal invoice_items_count + 2, InvoiceItem.count + assert_equal users_credit_count, UsersCredit.count + assert_equal wallet_transactions_count + 1, WalletTransaction.count + assert_equal Coupon.find_by(code: 'GIME3EUR').id, @cart1.coupon_id + + # invoice_items assertions + invoice_item = InvoiceItem.last + assert invoice_item.check_footprint + + # invoice assertions + invoice = Invoice.last + assert_invoice_pdf invoice + assert_not_nil invoice.debug_footprint + + assert invoice.payment_gateway_object.blank? + assert_not invoice.total.blank? + assert invoice.check_footprint + + # notification + assert_not_empty Notification.where(attached_object: invoice) + + # wallet + assert_equal 3, @pjproudhon.wallet.amount + assert_equal 2, @pjproudhon.wallet.wallet_transactions.count + transaction = @pjproudhon.wallet.wallet_transactions.last + assert_equal 'debit', transaction.transaction_type + assert_equal @cart1.paid_total, 0 + assert_equal @cart1.wallet_amount, 262_200 + assert_equal 2622, transaction.amount + end +end diff --git a/test/integration/store/user_pay_order_test.rb b/test/integration/store/user_pay_order_test.rb index 62420339d..6d72fc802 100644 --- a/test/integration/store/user_pay_order_test.rb +++ b/test/integration/store/user_pay_order_test.rb @@ -63,6 +63,69 @@ class Store::UserPayOrderTest < ActionDispatch::IntegrationTest assert_equal activity.operator_profile_id, @pjproudhon.invoicing_profile.id end + test 'user pay order by cart and wallet with success' do + login_as(@pjproudhon, scope: :user) + + service = WalletService.new(user: @admin, wallet: @pjproudhon.wallet) + service.credit(1) + + invoice_count = Invoice.count + invoice_items_count = InvoiceItem.count + users_credit_count = UsersCredit.count + wallet_transactions_count = WalletTransaction.count + + VCR.use_cassette('store_order_pay_by_cart_and_wallet_success') do + post '/api/checkout/payment', + params: { + payment_id: stripe_payment_method, + order_token: @cart1.token + }.to_json, headers: default_headers + end + + @pjproudhon.wallet.reload + @cart1.reload + + # general assertions + assert_equal 200, response.status + assert_equal invoice_count + 1, Invoice.count + assert_equal invoice_items_count + 1, InvoiceItem.count + + # invoice_items assertions + invoice_item = InvoiceItem.last + + assert invoice_item.check_footprint + + # invoice assertions + invoice = Invoice.last + assert_invoice_pdf invoice + assert_not_nil invoice.debug_footprint + + assert_not @cart1.payment_gateway_object.blank? + assert_not invoice.payment_gateway_object.blank? + assert_not invoice.total.blank? + assert invoice.check_footprint + + # notification + assert_not_empty Notification.where(attached_object: invoice) + + assert_equal @cart1.state, 'paid' + assert_equal @cart1.payment_method, 'card' + assert_equal @cart1.paid_total, 400 + assert_equal users_credit_count, UsersCredit.count + assert_equal wallet_transactions_count + 1, WalletTransaction.count + + # wallet + assert_equal 0, @pjproudhon.wallet.amount + assert_equal 2, @pjproudhon.wallet.wallet_transactions.count + transaction = @pjproudhon.wallet.wallet_transactions.last + assert_equal 'debit', transaction.transaction_type + assert_equal @cart1.paid_total, 400 + assert_equal @cart1.wallet_amount / 100.0, transaction.amount + assert_equal @cart1.payment_method, 'card' + assert_equal @cart1.wallet_transaction_id, transaction.id + assert_equal invoice.wallet_amount / 100.0, transaction.amount + end + test 'user pay order by wallet with success' do login_as(@pjproudhon, scope: :user) @@ -76,7 +139,6 @@ class Store::UserPayOrderTest < ActionDispatch::IntegrationTest post '/api/checkout/payment', params: { - # payment_method_id: stripe_payment_method, order_token: @cart1.token }.to_json, headers: default_headers @@ -133,7 +195,6 @@ class Store::UserPayOrderTest < ActionDispatch::IntegrationTest post '/api/checkout/payment', params: { - # payment_method_id: stripe_payment_method, order_token: @cart1.token, coupon_code: 'GIME3EUR' }.to_json, headers: default_headers diff --git a/test/services/cart/find_or_create_service_test.rb b/test/services/cart/find_or_create_service_test.rb index 82e0c5014..6659ab5ff 100644 --- a/test/services/cart/find_or_create_service_test.rb +++ b/test/services/cart/find_or_create_service_test.rb @@ -70,7 +70,7 @@ class Cart::FindOrCreateServiceTest < ActiveSupport::TestCase test 'admin get a cart' do cart = Cart::FindOrCreateService.new(@admin).call(nil) assert_equal cart.state, 'cart' - assert_equal cart.total, 261_500 + assert_equal cart.total, 262_500 assert_equal cart.operator_profile_id, @admin.invoicing_profile.id assert_nil cart.statistic_profile_id assert_equal Order.where(operator_profile_id: @admin.invoicing_profile.id, state: 'cart').count, 1 diff --git a/test/services/cart/set_offer_service_test.rb b/test/services/cart/set_offer_service_test.rb index 85ba0af4f..925aec162 100644 --- a/test/services/cart/set_offer_service_test.rb +++ b/test/services/cart/set_offer_service_test.rb @@ -5,20 +5,20 @@ require 'test_helper' class Cart::SetOfferServiceTest < ActiveSupport::TestCase setup do @caisse_en_bois = Product.find_by(slug: 'caisse-en-bois') - @panneaux = Product.find_by(slug: 'panneaux-de-mdf') + @filament = Product.find_by(slug: 'filament-pla-blanc') @cart = Order.find_by(token: '0DKxbAOzSXRx-amXyhmDdg1666691976019') end test 'set offer product in cart' do cart = Cart::SetOfferService.new.call(@cart, @caisse_en_bois, true) - assert_equal cart.total, 0 + assert_equal cart.total, 1000 assert_equal cart.order_items.first.amount, @caisse_en_bois.amount assert_equal cart.order_items.first.is_offered, true end test 'cannot set offer if product that isnt in cart' do assert_raise ActiveRecord::RecordNotFound do - Cart::SetOfferService.new.call(@cart, @panneaux, true) + Cart::SetOfferService.new.call(@cart, @filament, true) end end end diff --git a/test/vcr_cassettes/store_order_admin_pay_by_cart_and_wallet_success.yml b/test/vcr_cassettes/store_order_admin_pay_by_cart_and_wallet_success.yml new file mode 100644 index 000000000..450b56403 --- /dev/null +++ b/test/vcr_cassettes/store_order_admin_pay_by_cart_and_wallet_success.yml @@ -0,0 +1,338 @@ +--- +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.3 p62 (2019-04-16)","platform":"x86_64-darwin18","engine":"ruby","publisher":"stripe","uname":"Darwin + MacBook-Pro-Sleede-Peng 20.6.0 Darwin Kernel Version 20.6.0: Thu Sep 29 20:15:11 + PDT 2022; root:xnu-7195.141.42~1/RELEASE_X86_64 x86_64","hostname":"MacBook-Pro-Sleede-Peng"}' + 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: + - Mon, 07 Nov 2022 17:22:23 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: + - 3d420ca2-b79a-451b-88bc-56efb989ae3e + Original-Request: + - req_7tnZKRYjblvjJF + Request-Id: + - req_7tnZKRYjblvjJF + Stripe-Should-Retry: + - 'false' + Stripe-Version: + - '2019-08-14' + Strict-Transport-Security: + - max-age=63072000; includeSubDomains; preload + body: + encoding: UTF-8 + string: |- + { + "id": "pm_1M1Z1f2sOmf47Nz9y4qaYQap", + "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": 1667841743, + "customer": null, + "livemode": false, + "metadata": {}, + "type": "card" + } + recorded_at: Mon, 07 Nov 2022 17:22:24 GMT +- request: + method: post + uri: https://api.stripe.com/v1/payment_intents + body: + encoding: UTF-8 + string: payment_method=pm_1M1Z1f2sOmf47Nz9y4qaYQap&amount=162500¤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_7tnZKRYjblvjJF","request_duration_ms":697}}' + Stripe-Version: + - '2019-08-14' + X-Stripe-Client-User-Agent: + - '{"bindings_version":"5.29.0","lang":"ruby","lang_version":"2.6.3 p62 (2019-04-16)","platform":"x86_64-darwin18","engine":"ruby","publisher":"stripe","uname":"Darwin + MacBook-Pro-Sleede-Peng 20.6.0 Darwin Kernel Version 20.6.0: Thu Sep 29 20:15:11 + PDT 2022; root:xnu-7195.141.42~1/RELEASE_X86_64 x86_64","hostname":"MacBook-Pro-Sleede-Peng"}' + 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: + - Mon, 07 Nov 2022 17:22:25 GMT + Content-Type: + - application/json + Content-Length: + - '4476' + 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: + - 5294d6d7-d766-4aa5-bac1-be52f491fa20 + Original-Request: + - req_c0S6XFCR5hlcc9 + Request-Id: + - req_c0S6XFCR5hlcc9 + Stripe-Should-Retry: + - 'false' + Stripe-Version: + - '2019-08-14' + Strict-Transport-Security: + - max-age=63072000; includeSubDomains; preload + body: + encoding: UTF-8 + string: |- + { + "id": "pi_3M1Z1g2sOmf47Nz91KcAbrWR", + "object": "payment_intent", + "amount": 162500, + "amount_capturable": 0, + "amount_details": { + "tip": {} + }, + "amount_received": 162500, + "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_3M1Z1g2sOmf47Nz91YJQvMPK", + "object": "charge", + "amount": 162500, + "amount_captured": 162500, + "amount_refunded": 0, + "application": null, + "application_fee": null, + "application_fee_amount": null, + "balance_transaction": "txn_3M1Z1g2sOmf47Nz913ZvXNvF", + "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": 1667841744, + "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": 45, + "seller_message": "Payment complete.", + "type": "authorized" + }, + "paid": true, + "payment_intent": "pi_3M1Z1g2sOmf47Nz91KcAbrWR", + "payment_method": "pm_1M1Z1f2sOmf47Nz9y4qaYQap", + "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/CAcaFwoVYWNjdF8xMDNyRTYyc09tZjQ3Tno5KNH9pJsGMgbMAdBS9Kg6LBbMQFUWP1mmaiHjAUCgW-WYHRH5dwIHTlYhiTVjiSL5fqEMQr17GSJhWPA-", + "refunded": false, + "refunds": { + "object": "list", + "data": [], + "has_more": false, + "total_count": 0, + "url": "/v1/charges/ch_3M1Z1g2sOmf47Nz91YJQvMPK/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_3M1Z1g2sOmf47Nz91KcAbrWR" + }, + "client_secret": "pi_3M1Z1g2sOmf47Nz91KcAbrWR_secret_ocSaI8LfCIvNBzfXl5iwRB9kS", + "confirmation_method": "manual", + "created": 1667841744, + "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_1M1Z1f2sOmf47Nz9y4qaYQap", + "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: Mon, 07 Nov 2022 17:22:26 GMT +recorded_with: VCR 6.0.0 diff --git a/test/vcr_cassettes/store_order_admin_pay_by_cart_success.yml b/test/vcr_cassettes/store_order_admin_pay_by_cart_success.yml new file mode 100644 index 000000000..da812fed8 --- /dev/null +++ b/test/vcr_cassettes/store_order_admin_pay_by_cart_success.yml @@ -0,0 +1,340 @@ +--- +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 + X-Stripe-Client-Telemetry: + - '{"last_request_metrics":{"request_id":"req_RmcFNPXaqrPUG5","request_duration_ms":2}}' + Stripe-Version: + - '2019-08-14' + X-Stripe-Client-User-Agent: + - '{"bindings_version":"5.29.0","lang":"ruby","lang_version":"2.6.3 p62 (2019-04-16)","platform":"x86_64-darwin18","engine":"ruby","publisher":"stripe","uname":"Darwin + MacBook-Pro-Sleede-Peng 20.6.0 Darwin Kernel Version 20.6.0: Thu Sep 29 20:15:11 + PDT 2022; root:xnu-7195.141.42~1/RELEASE_X86_64 x86_64","hostname":"MacBook-Pro-Sleede-Peng"}' + 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: + - Mon, 07 Nov 2022 16:37:43 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: + - 79f4b0fa-8f75-413e-9d49-d676004060f3 + Original-Request: + - req_XjXHG1cRekGj4r + Request-Id: + - req_XjXHG1cRekGj4r + Stripe-Should-Retry: + - 'false' + Stripe-Version: + - '2019-08-14' + Strict-Transport-Security: + - max-age=63072000; includeSubDomains; preload + body: + encoding: UTF-8 + string: |- + { + "id": "pm_1M1YKR2sOmf47Nz9zhudFmj4", + "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": 1667839063, + "customer": null, + "livemode": false, + "metadata": {}, + "type": "card" + } + recorded_at: Mon, 07 Nov 2022 16:37:43 GMT +- request: + method: post + uri: https://api.stripe.com/v1/payment_intents + body: + encoding: UTF-8 + string: payment_method=pm_1M1YKR2sOmf47Nz9zhudFmj4&amount=262500¤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_XjXHG1cRekGj4r","request_duration_ms":747}}' + Stripe-Version: + - '2019-08-14' + X-Stripe-Client-User-Agent: + - '{"bindings_version":"5.29.0","lang":"ruby","lang_version":"2.6.3 p62 (2019-04-16)","platform":"x86_64-darwin18","engine":"ruby","publisher":"stripe","uname":"Darwin + MacBook-Pro-Sleede-Peng 20.6.0 Darwin Kernel Version 20.6.0: Thu Sep 29 20:15:11 + PDT 2022; root:xnu-7195.141.42~1/RELEASE_X86_64 x86_64","hostname":"MacBook-Pro-Sleede-Peng"}' + 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: + - Mon, 07 Nov 2022 16:37:45 GMT + Content-Type: + - application/json + Content-Length: + - '4476' + 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: + - e3937b40-2f56-48ad-a6f0-45cd4f8561b6 + Original-Request: + - req_OOfatPeQh69g1l + Request-Id: + - req_OOfatPeQh69g1l + Stripe-Should-Retry: + - 'false' + Stripe-Version: + - '2019-08-14' + Strict-Transport-Security: + - max-age=63072000; includeSubDomains; preload + body: + encoding: UTF-8 + string: |- + { + "id": "pi_3M1YKR2sOmf47Nz91drXiltW", + "object": "payment_intent", + "amount": 262500, + "amount_capturable": 0, + "amount_details": { + "tip": {} + }, + "amount_received": 262500, + "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_3M1YKR2sOmf47Nz91vWs1pmT", + "object": "charge", + "amount": 262500, + "amount_captured": 262500, + "amount_refunded": 0, + "application": null, + "application_fee": null, + "application_fee_amount": null, + "balance_transaction": "txn_3M1YKR2sOmf47Nz91H5LYpIY", + "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": 1667839064, + "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": 45, + "seller_message": "Payment complete.", + "type": "authorized" + }, + "paid": true, + "payment_intent": "pi_3M1YKR2sOmf47Nz91drXiltW", + "payment_method": "pm_1M1YKR2sOmf47Nz9zhudFmj4", + "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/CAcaFwoVYWNjdF8xMDNyRTYyc09tZjQ3Tno5KNnopJsGMgYH2kV57SE6LBZXrW4wqlWRDUWQvuladk_TMDrnHcxaLwpAjVvyXY2T71ztlsFRB6pt77PJ", + "refunded": false, + "refunds": { + "object": "list", + "data": [], + "has_more": false, + "total_count": 0, + "url": "/v1/charges/ch_3M1YKR2sOmf47Nz91vWs1pmT/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_3M1YKR2sOmf47Nz91drXiltW" + }, + "client_secret": "pi_3M1YKR2sOmf47Nz91drXiltW_secret_0gbfWYm7cOart4zGoozKDSQP0", + "confirmation_method": "manual", + "created": 1667839063, + "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_1M1YKR2sOmf47Nz9zhudFmj4", + "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: Mon, 07 Nov 2022 16:37:45 GMT +recorded_with: VCR 6.0.0 diff --git a/test/vcr_cassettes/store_order_pay_by_cart_and_wallet_success.yml b/test/vcr_cassettes/store_order_pay_by_cart_and_wallet_success.yml new file mode 100644 index 000000000..f7b9c8045 --- /dev/null +++ b/test/vcr_cassettes/store_order_pay_by_cart_and_wallet_success.yml @@ -0,0 +1,338 @@ +--- +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.3 p62 (2019-04-16)","platform":"x86_64-darwin18","engine":"ruby","publisher":"stripe","uname":"Darwin + MacBook-Pro-Sleede-Peng 20.6.0 Darwin Kernel Version 20.6.0: Thu Sep 29 20:15:11 + PDT 2022; root:xnu-7195.141.42~1/RELEASE_X86_64 x86_64","hostname":"MacBook-Pro-Sleede-Peng"}' + 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: + - Mon, 07 Nov 2022 17:46:28 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: + - 1f9773d4-f524-44dc-90f2-dde90fea1744 + Original-Request: + - req_Fbkchw5l1kFzvM + Request-Id: + - req_Fbkchw5l1kFzvM + Stripe-Should-Retry: + - 'false' + Stripe-Version: + - '2019-08-14' + Strict-Transport-Security: + - max-age=63072000; includeSubDomains; preload + body: + encoding: UTF-8 + string: |- + { + "id": "pm_1M1ZOy2sOmf47Nz9S0LQW3tB", + "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": 1667843188, + "customer": null, + "livemode": false, + "metadata": {}, + "type": "card" + } + recorded_at: Mon, 07 Nov 2022 17:46:28 GMT +- request: + method: post + uri: https://api.stripe.com/v1/payment_intents + body: + encoding: UTF-8 + string: payment_method=pm_1M1ZOy2sOmf47Nz9S0LQW3tB&amount=400¤cy=usd&confirmation_method=manual&confirm=true&customer=cus_IhIynmoJbzLpwX + 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_Fbkchw5l1kFzvM","request_duration_ms":681}}' + Stripe-Version: + - '2019-08-14' + X-Stripe-Client-User-Agent: + - '{"bindings_version":"5.29.0","lang":"ruby","lang_version":"2.6.3 p62 (2019-04-16)","platform":"x86_64-darwin18","engine":"ruby","publisher":"stripe","uname":"Darwin + MacBook-Pro-Sleede-Peng 20.6.0 Darwin Kernel Version 20.6.0: Thu Sep 29 20:15:11 + PDT 2022; root:xnu-7195.141.42~1/RELEASE_X86_64 x86_64","hostname":"MacBook-Pro-Sleede-Peng"}' + 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: + - Mon, 07 Nov 2022 17:46:31 GMT + Content-Type: + - application/json + Content-Length: + - '4464' + 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: + - 9452e086-c4bb-4c4e-94fe-ddef5a8f8cc1 + Original-Request: + - req_GIkX2D4yu7OXRO + Request-Id: + - req_GIkX2D4yu7OXRO + Stripe-Should-Retry: + - 'false' + Stripe-Version: + - '2019-08-14' + Strict-Transport-Security: + - max-age=63072000; includeSubDomains; preload + body: + encoding: UTF-8 + string: |- + { + "id": "pi_3M1ZOz2sOmf47Nz90tK9gllB", + "object": "payment_intent", + "amount": 400, + "amount_capturable": 0, + "amount_details": { + "tip": {} + }, + "amount_received": 400, + "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_3M1ZOz2sOmf47Nz90wkd0Upl", + "object": "charge", + "amount": 400, + "amount_captured": 400, + "amount_refunded": 0, + "application": null, + "application_fee": null, + "application_fee_amount": null, + "balance_transaction": "txn_3M1ZOz2sOmf47Nz90XN9Q2k6", + "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": 1667843190, + "currency": "usd", + "customer": "cus_IhIynmoJbzLpwX", + "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": 49, + "seller_message": "Payment complete.", + "type": "authorized" + }, + "paid": true, + "payment_intent": "pi_3M1ZOz2sOmf47Nz90tK9gllB", + "payment_method": "pm_1M1ZOy2sOmf47Nz9S0LQW3tB", + "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/CAcaFwoVYWNjdF8xMDNyRTYyc09tZjQ3Tno5KPaIpZsGMgYxLskxGmo6LBa54zBFlRI8uQmwFIdZImPLTv2fAl6N6X554JBe_MnNGACgZ-jJ5M4MYK4R", + "refunded": false, + "refunds": { + "object": "list", + "data": [], + "has_more": false, + "total_count": 0, + "url": "/v1/charges/ch_3M1ZOz2sOmf47Nz90wkd0Upl/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_3M1ZOz2sOmf47Nz90tK9gllB" + }, + "client_secret": "pi_3M1ZOz2sOmf47Nz90tK9gllB_secret_8DSGuKQHUpisoFx6hdLYsPtTy", + "confirmation_method": "manual", + "created": 1667843189, + "currency": "usd", + "customer": "cus_IhIynmoJbzLpwX", + "description": null, + "invoice": null, + "last_payment_error": null, + "livemode": false, + "metadata": {}, + "next_action": null, + "on_behalf_of": null, + "payment_method": "pm_1M1ZOy2sOmf47Nz9S0LQW3tB", + "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: Mon, 07 Nov 2022 17:46:31 GMT +recorded_with: VCR 6.0.0