1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

check coupon code server side + integration test for wrong copon

This commit is contained in:
Sylvain 2016-09-08 15:19:12 +02:00
parent c6d9cbd88d
commit d233297469
7 changed files with 1092 additions and 35 deletions

View File

@ -20,19 +20,23 @@ class API::ReservationsController < API::ApiController
end
def create
if current_user.is_admin?
@reservation = Reservation.new(reservation_params)
is_reserve = @reservation.save_with_local_payment(coupon_params[:coupon_code])
else
@reservation = Reservation.new(reservation_params.merge(user_id: current_user.id))
is_reserve = @reservation.save_with_payment(coupon_params[:coupon_code])
end
if is_reserve
SubscriptionExtensionAfterReservation.new(@reservation).extend_subscription_if_eligible
begin
if current_user.is_admin?
@reservation = Reservation.new(reservation_params)
is_reserve = @reservation.save_with_local_payment(coupon_params[:coupon_code])
else
@reservation = Reservation.new(reservation_params.merge(user_id: current_user.id))
is_reserve = @reservation.save_with_payment(coupon_params[:coupon_code])
end
if is_reserve
SubscriptionExtensionAfterReservation.new(@reservation).extend_subscription_if_eligible
render :show, status: :created, location: @reservation
else
render json: @reservation.errors, status: :unprocessable_entity
render :show, status: :created, location: @reservation
else
render json: @reservation.errors, status: :unprocessable_entity
end
rescue InvalidCouponError
render json: {coupon_code: 'wrong coupon code or expired'}, status: :unprocessable_entity
end
end

View File

@ -0,0 +1,3 @@
# Raised when using a coupon expired or invalid
class InvalidCouponError < StandardError
end

View File

@ -131,14 +131,18 @@ class Reservation < ActiveRecord::Base
# === Coupon ===
unless coupon_code.nil?
cp = Coupon.find_by_code(coupon_code)
total = invoice.invoice_items.map(&:amount).map(&:to_i).reduce(:+)
unless on_site
invoice_items << Stripe::InvoiceItem.create(
customer: user.stp_customer_id,
amount: -(total * cp.percent_off / 100).to_i,
currency: Rails.application.secrets.stripe_currency,
description: "coupon #{cp.code}"
)
if not cp.nil? and cp.status(user.id) == 'active'
total = invoice.invoice_items.map(&:amount).map(&:to_i).reduce(:+)
unless on_site
invoice_items << Stripe::InvoiceItem.create(
customer: user.stp_customer_id,
amount: -(total * cp.percent_off / 100).to_i,
currency: Rails.application.secrets.stripe_currency,
description: "coupon #{cp.code}"
)
end
else
raise InvalidCouponError
end
end
@ -410,8 +414,12 @@ class Reservation < ActiveRecord::Base
unless coupon_code.nil?
cp = Coupon.find_by_code(coupon_code)
total = total - (total * cp.percent_off / 100.0)
self.invoice.coupon_id = cp.id
if not cp.nil? and cp.status(user.id) == 'active'
total = total - (total * cp.percent_off / 100.0)
self.invoice.coupon_id = cp.id
else
raise InvalidCouponError
end
end
self.invoice.total = total

View File

@ -36,6 +36,23 @@ class Subscription < ActiveRecord::Base
unless coupon_code.nil?
cp = Coupon.find_by_code(coupon_code)
if not cp.nil? and cp.status(user.id) == 'active'
total = plan.amount
Stripe::InvoiceItem.create(
customer: user.stp_customer_id,
amount: -(total * cp.percent_off / 100.0).to_i,
currency: Rails.application.secrets.stripe_currency,
description: "coupon #{cp.code}"
)
else
raise InvalidCouponError
end
end
elsif coupon_code != nil
# this case applies if a subscription was took in addition of a reservation, so we create a second
# stripe coupon to apply the discount on the subscription item for the stripe's invoice.
cp = Coupon.find_by_code(coupon_code)
if not cp.nil? and cp.status(user.id) == 'active'
total = plan.amount
Stripe::InvoiceItem.create(
customer: user.stp_customer_id,
@ -43,18 +60,9 @@ class Subscription < ActiveRecord::Base
currency: Rails.application.secrets.stripe_currency,
description: "coupon #{cp.code}"
)
else
raise InvalidCouponError
end
elsif coupon_code != nil
# this case applies if a subscription was took in addition of a reservation, so we create a second
# stripe coupon to apply the discount on the subscription item for the stripe's invoice.
cp = Coupon.find_by_code(coupon_code)
total = plan.amount
Stripe::InvoiceItem.create(
customer: user.stp_customer_id,
amount: -(total * cp.percent_off / 100.0).to_i,
currency: Rails.application.secrets.stripe_currency,
description: "coupon #{cp.code}"
)
end
new_subscription = customer.subscriptions.create(plan: plan.stp_plan_id, source: card_token)

View File

@ -40,8 +40,8 @@ development:
test:
secret_key_base: 83daf5e7b80d990f037407bab78dff9904aaf3c195a50f84fa8695a22287e707dfbd9524b403b1dcf116ae1d8c06844c3d7ed942564e5b46be6ae3ead93a9d30
stripe_api_key: <%= ENV["STRIPE_API_KEY"] %>
stripe_publishable_key: <%= ENV["STRIPE_PUBLISHABLE_KEY"] %>
stripe_api_key: sk_test_mGokO9TGtrVxMOyK4yZiktBE
stripe_publishable_key: pk_test_aScrMu3y4AocfCN5XLJjGzmQ
stripe_currency: usd
disqus_shortname: fablab-sleede
fablab_without_plans: false

View File

@ -517,5 +517,42 @@ module Reservations
assert_not_empty Notification.where(attached_object: reservation)
assert_not_empty Notification.where(attached_object: subscription)
end
test 'user reserves a training with an expired coupon with error' do
login_as(@user_without_subscription, scope: :user)
training = Training.find(1)
availability = training.availabilities.first
reservations_count = Reservation.count
invoice_count = Invoice.count
invoice_items_count = InvoiceItem.count
notifications_count = Notification.count
VCR.use_cassette('reservations_training_with_expired_coupon_error') do
post reservations_path, {
reservation: {
user_id: @user_without_subscription.id,
reservable_id: training.id,
reservable_type: training.class.name,
card_token: stripe_card_token,
slots_attributes: [
{ start_at: availability.start_at.to_s(:iso8601),
end_at: (availability.start_at + 1.hour).to_s(:iso8601),
availability_id: availability.id
}
],
},
coupon_code: 'XMAS10'
}.to_json, default_headers
end
# general assertions
assert_equal 422, response.status
assert_equal reservations_count, Reservation.count
assert_equal invoice_count, Invoice.count
assert_equal invoice_items_count, InvoiceItem.count
assert_equal notifications_count, Notification.count
end
end
end

View File

@ -0,0 +1,997 @@
---
http_interactions:
- request:
method: post
uri: https://api.stripe.com/v1/tokens
body:
encoding: UTF-8
string: card[number]=4242424242424242&card[exp_month]=4&card[exp_year]=2017&card[cvc]=314
headers:
Accept:
- "*/*; q=0.5, application/xml"
Accept-Encoding:
- gzip, deflate
User-Agent:
- Stripe/v1 RubyBindings/1.30.2
Authorization:
- Bearer sk_test_mGokO9TGtrVxMOyK4yZiktBE
Content-Type:
- application/x-www-form-urlencoded
X-Stripe-Client-User-Agent:
- '{"bindings_version":"1.30.2","lang":"ruby","lang_version":"2.3.0 p0 (2015-12-25)","platform":"x86_64-linux","engine":"ruby","publisher":"stripe","uname":"Linux
version 4.4.0-36-generic (buildd@lcy01-01) (gcc version 5.4.0 20160609 (Ubuntu
5.4.0-6ubuntu1~16.04.2) ) #55-Ubuntu SMP Thu Aug 11 18:01:55 UTC 2016","hostname":"sylvain-sleede-pc"}'
Content-Length:
- '81'
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Thu, 08 Sep 2016 12:45:30 GMT
Content-Type:
- application/json
Content-Length:
- '779'
Connection:
- keep-alive
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Methods:
- GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Allow-Origin:
- "*"
Access-Control-Max-Age:
- '300'
Cache-Control:
- no-cache, no-store
Request-Id:
- req_99lRiyf8VYL75c
Stripe-Version:
- '2015-10-16'
Strict-Transport-Security:
- max-age=31556926; includeSubDomains
body:
encoding: UTF-8
string: |
{
"id": "tok_18rRuI2sOmf47Nz9nl5ZXXoF",
"object": "token",
"card": {
"id": "card_18rRuI2sOmf47Nz9TSeEZ96o",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"cvc_check": "unchecked",
"dynamic_last4": null,
"exp_month": 4,
"exp_year": 2017,
"fingerprint": "o52jybR7bnmNn6AT",
"funding": "credit",
"last4": "4242",
"metadata": {},
"name": null,
"tokenization_method": null
},
"client_ip": "90.52.44.103",
"created": 1473338730,
"livemode": false,
"type": "card",
"used": false
}
http_version:
recorded_at: Thu, 08 Sep 2016 12:45:30 GMT
- request:
method: post
uri: https://api.stripe.com/v1/invoiceitems
body:
encoding: UTF-8
string: customer=cus_8Di1wjdVktv5kt&amount=5100&currency=usd&description=Formation+Imprimante+3D+September+05%2C+2016+08%3A00+-+09%3A00+AM
headers:
Accept:
- "*/*; q=0.5, application/xml"
Accept-Encoding:
- gzip, deflate
User-Agent:
- Stripe/v1 RubyBindings/1.30.2
Authorization:
- Bearer sk_test_mGokO9TGtrVxMOyK4yZiktBE
Content-Type:
- application/x-www-form-urlencoded
X-Stripe-Client-User-Agent:
- '{"bindings_version":"1.30.2","lang":"ruby","lang_version":"2.3.0 p0 (2015-12-25)","platform":"x86_64-linux","engine":"ruby","publisher":"stripe","uname":"Linux
version 4.4.0-36-generic (buildd@lcy01-01) (gcc version 5.4.0 20160609 (Ubuntu
5.4.0-6ubuntu1~16.04.2) ) #55-Ubuntu SMP Thu Aug 11 18:01:55 UTC 2016","hostname":"sylvain-sleede-pc"}'
Content-Length:
- '130'
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Thu, 08 Sep 2016 12:45:31 GMT
Content-Type:
- application/json
Content-Length:
- '476'
Connection:
- keep-alive
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Methods:
- GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Allow-Origin:
- "*"
Access-Control-Max-Age:
- '300'
Cache-Control:
- no-cache, no-store
Request-Id:
- req_99lRUe4QZ7kRSv
Stripe-Version:
- '2015-10-16'
Strict-Transport-Security:
- max-age=31556926; includeSubDomains
body:
encoding: UTF-8
string: |
{
"id": "ii_18rRuJ2sOmf47Nz9S7f6qfEz",
"object": "invoiceitem",
"amount": 5100,
"currency": "usd",
"customer": "cus_8Di1wjdVktv5kt",
"date": 1473338731,
"description": "Formation Imprimante 3D September 05, 2016 08:00 - 09:00 AM",
"discountable": true,
"invoice": null,
"livemode": false,
"metadata": {},
"period": {
"start": 1473338731,
"end": 1473338731
},
"plan": null,
"proration": false,
"quantity": null,
"subscription": null
}
http_version:
recorded_at: Thu, 08 Sep 2016 12:45:31 GMT
- request:
method: post
uri: https://api.stripe.com/v1/invoiceitems
body:
encoding: UTF-8
string: customer=cus_8Di1wjdVktv5kt&amount=-510&currency=usd&description=coupon+XMAS10
headers:
Accept:
- "*/*; q=0.5, application/xml"
Accept-Encoding:
- gzip, deflate
User-Agent:
- Stripe/v1 RubyBindings/1.30.2
Authorization:
- Bearer sk_test_mGokO9TGtrVxMOyK4yZiktBE
Content-Type:
- application/x-www-form-urlencoded
X-Stripe-Client-User-Agent:
- '{"bindings_version":"1.30.2","lang":"ruby","lang_version":"2.3.0 p0 (2015-12-25)","platform":"x86_64-linux","engine":"ruby","publisher":"stripe","uname":"Linux
version 4.4.0-36-generic (buildd@lcy01-01) (gcc version 5.4.0 20160609 (Ubuntu
5.4.0-6ubuntu1~16.04.2) ) #55-Ubuntu SMP Thu Aug 11 18:01:55 UTC 2016","hostname":"sylvain-sleede-pc"}'
Content-Length:
- '78'
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Thu, 08 Sep 2016 12:45:32 GMT
Content-Type:
- application/json
Content-Length:
- '431'
Connection:
- keep-alive
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Methods:
- GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Allow-Origin:
- "*"
Access-Control-Max-Age:
- '300'
Cache-Control:
- no-cache, no-store
Request-Id:
- req_99lR2huyf6IhVY
Stripe-Version:
- '2015-10-16'
Strict-Transport-Security:
- max-age=31556926; includeSubDomains
body:
encoding: UTF-8
string: |
{
"id": "ii_18rRuK2sOmf47Nz9ye4DQ4PM",
"object": "invoiceitem",
"amount": -510,
"currency": "usd",
"customer": "cus_8Di1wjdVktv5kt",
"date": 1473338732,
"description": "coupon XMAS10",
"discountable": false,
"invoice": null,
"livemode": false,
"metadata": {},
"period": {
"start": 1473338732,
"end": 1473338732
},
"plan": null,
"proration": false,
"quantity": null,
"subscription": null
}
http_version:
recorded_at: Thu, 08 Sep 2016 12:45:32 GMT
- request:
method: get
uri: https://api.stripe.com/v1/customers/cus_8Di1wjdVktv5kt
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- "*/*; q=0.5, application/xml"
Accept-Encoding:
- gzip, deflate
User-Agent:
- Stripe/v1 RubyBindings/1.30.2
Authorization:
- Bearer sk_test_mGokO9TGtrVxMOyK4yZiktBE
Content-Type:
- application/x-www-form-urlencoded
X-Stripe-Client-User-Agent:
- '{"bindings_version":"1.30.2","lang":"ruby","lang_version":"2.3.0 p0 (2015-12-25)","platform":"x86_64-linux","engine":"ruby","publisher":"stripe","uname":"Linux
version 4.4.0-36-generic (buildd@lcy01-01) (gcc version 5.4.0 20160609 (Ubuntu
5.4.0-6ubuntu1~16.04.2) ) #55-Ubuntu SMP Thu Aug 11 18:01:55 UTC 2016","hostname":"sylvain-sleede-pc"}'
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Thu, 08 Sep 2016 12:45:33 GMT
Content-Type:
- application/json
Content-Length:
- '2495'
Connection:
- keep-alive
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Methods:
- GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Allow-Origin:
- "*"
Access-Control-Max-Age:
- '300'
Cache-Control:
- no-cache, no-store
Request-Id:
- req_99lRlUD2wtvAmA
Stripe-Version:
- '2015-10-16'
Strict-Transport-Security:
- max-age=31556926; includeSubDomains
body:
encoding: UTF-8
string: |
{
"id": "cus_8Di1wjdVktv5kt",
"object": "customer",
"account_balance": 0,
"created": 1459948888,
"currency": "usd",
"default_source": "card_18rNSk2sOmf47Nz9h1cf7obf",
"delinquent": false,
"description": "Jean Dupond",
"discount": null,
"email": "jean.dupond@gmail.com",
"livemode": false,
"metadata": {},
"shipping": null,
"sources": {
"object": "list",
"data": [
{
"id": "card_18rNSk2sOmf47Nz9h1cf7obf",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": "cus_8Di1wjdVktv5kt",
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 4,
"exp_year": 2017,
"fingerprint": "o52jybR7bnmNn6AT",
"funding": "credit",
"last4": "4242",
"metadata": {},
"name": null,
"tokenization_method": null
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/customers/cus_8Di1wjdVktv5kt/sources"
},
"subscriptions": {
"object": "list",
"data": [
{
"id": "sub_99gqb47NmX9r79",
"object": "subscription",
"application_fee_percent": null,
"cancel_at_period_end": true,
"canceled_at": 1473321656,
"created": 1473321652,
"current_period_end": 1475913652,
"current_period_start": 1473321652,
"customer": "cus_8Di1wjdVktv5kt",
"discount": null,
"ended_at": null,
"livemode": false,
"metadata": {},
"plan": {
"id": "mensuel-standard-month-20160404171519",
"object": "plan",
"amount": 3000,
"created": 1459782921,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {},
"name": "Mensuel - standard, association - month",
"statement_descriptor": null,
"trial_period_days": null
},
"quantity": 1,
"start": 1473321652,
"status": "active",
"tax_percent": null,
"trial_end": null,
"trial_start": null
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/customers/cus_8Di1wjdVktv5kt/subscriptions"
}
}
http_version:
recorded_at: Thu, 08 Sep 2016 12:45:33 GMT
- request:
method: post
uri: https://api.stripe.com/v1/customers/cus_8Di1wjdVktv5kt/sources
body:
encoding: UTF-8
string: card=tok_18rRuI2sOmf47Nz9nl5ZXXoF
headers:
Accept:
- "*/*; q=0.5, application/xml"
Accept-Encoding:
- gzip, deflate
User-Agent:
- Stripe/v1 RubyBindings/1.30.2
Authorization:
- Bearer sk_test_mGokO9TGtrVxMOyK4yZiktBE
Content-Type:
- application/x-www-form-urlencoded
X-Stripe-Client-User-Agent:
- '{"bindings_version":"1.30.2","lang":"ruby","lang_version":"2.3.0 p0 (2015-12-25)","platform":"x86_64-linux","engine":"ruby","publisher":"stripe","uname":"Linux
version 4.4.0-36-generic (buildd@lcy01-01) (gcc version 5.4.0 20160609 (Ubuntu
5.4.0-6ubuntu1~16.04.2) ) #55-Ubuntu SMP Thu Aug 11 18:01:55 UTC 2016","hostname":"sylvain-sleede-pc"}'
Content-Length:
- '33'
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Thu, 08 Sep 2016 12:45:34 GMT
Content-Type:
- application/json
Content-Length:
- '577'
Connection:
- keep-alive
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Methods:
- GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Allow-Origin:
- "*"
Access-Control-Max-Age:
- '300'
Cache-Control:
- no-cache, no-store
Request-Id:
- req_99lReB7yNLWrc3
Stripe-Version:
- '2015-10-16'
Strict-Transport-Security:
- max-age=31556926; includeSubDomains
body:
encoding: UTF-8
string: |
{
"id": "card_18rRuI2sOmf47Nz9TSeEZ96o",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": "cus_8Di1wjdVktv5kt",
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 4,
"exp_year": 2017,
"fingerprint": "o52jybR7bnmNn6AT",
"funding": "credit",
"last4": "4242",
"metadata": {},
"name": null,
"tokenization_method": null
}
http_version:
recorded_at: Thu, 08 Sep 2016 12:45:34 GMT
- request:
method: post
uri: https://api.stripe.com/v1/customers/cus_8Di1wjdVktv5kt
body:
encoding: UTF-8
string: default_source=card_18rRuI2sOmf47Nz9TSeEZ96o
headers:
Accept:
- "*/*; q=0.5, application/xml"
Accept-Encoding:
- gzip, deflate
User-Agent:
- Stripe/v1 RubyBindings/1.30.2
Authorization:
- Bearer sk_test_mGokO9TGtrVxMOyK4yZiktBE
Content-Type:
- application/x-www-form-urlencoded
X-Stripe-Client-User-Agent:
- '{"bindings_version":"1.30.2","lang":"ruby","lang_version":"2.3.0 p0 (2015-12-25)","platform":"x86_64-linux","engine":"ruby","publisher":"stripe","uname":"Linux
version 4.4.0-36-generic (buildd@lcy01-01) (gcc version 5.4.0 20160609 (Ubuntu
5.4.0-6ubuntu1~16.04.2) ) #55-Ubuntu SMP Thu Aug 11 18:01:55 UTC 2016","hostname":"sylvain-sleede-pc"}'
Content-Length:
- '44'
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Thu, 08 Sep 2016 12:45:35 GMT
Content-Type:
- application/json
Content-Length:
- '3223'
Connection:
- keep-alive
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Methods:
- GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Allow-Origin:
- "*"
Access-Control-Max-Age:
- '300'
Cache-Control:
- no-cache, no-store
Request-Id:
- req_99lRU3qBXW4qEB
Stripe-Version:
- '2015-10-16'
Strict-Transport-Security:
- max-age=31556926; includeSubDomains
body:
encoding: UTF-8
string: |
{
"id": "cus_8Di1wjdVktv5kt",
"object": "customer",
"account_balance": 0,
"created": 1459948888,
"currency": "usd",
"default_source": "card_18rRuI2sOmf47Nz9TSeEZ96o",
"delinquent": false,
"description": "Jean Dupond",
"discount": null,
"email": "jean.dupond@gmail.com",
"livemode": false,
"metadata": {},
"shipping": null,
"sources": {
"object": "list",
"data": [
{
"id": "card_18rRuI2sOmf47Nz9TSeEZ96o",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": "cus_8Di1wjdVktv5kt",
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 4,
"exp_year": 2017,
"fingerprint": "o52jybR7bnmNn6AT",
"funding": "credit",
"last4": "4242",
"metadata": {},
"name": null,
"tokenization_method": null
},
{
"id": "card_18rNSk2sOmf47Nz9h1cf7obf",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": "cus_8Di1wjdVktv5kt",
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 4,
"exp_year": 2017,
"fingerprint": "o52jybR7bnmNn6AT",
"funding": "credit",
"last4": "4242",
"metadata": {},
"name": null,
"tokenization_method": null
}
],
"has_more": false,
"total_count": 2,
"url": "/v1/customers/cus_8Di1wjdVktv5kt/sources"
},
"subscriptions": {
"object": "list",
"data": [
{
"id": "sub_99gqb47NmX9r79",
"object": "subscription",
"application_fee_percent": null,
"cancel_at_period_end": true,
"canceled_at": 1473321656,
"created": 1473321652,
"current_period_end": 1475913652,
"current_period_start": 1473321652,
"customer": "cus_8Di1wjdVktv5kt",
"discount": null,
"ended_at": null,
"livemode": false,
"metadata": {},
"plan": {
"id": "mensuel-standard-month-20160404171519",
"object": "plan",
"amount": 3000,
"created": 1459782921,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {},
"name": "Mensuel - standard, association - month",
"statement_descriptor": null,
"trial_period_days": null
},
"quantity": 1,
"start": 1473321652,
"status": "active",
"tax_percent": null,
"trial_end": null,
"trial_start": null
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/customers/cus_8Di1wjdVktv5kt/subscriptions"
}
}
http_version:
recorded_at: Thu, 08 Sep 2016 12:45:35 GMT
- request:
method: post
uri: https://api.stripe.com/v1/invoices
body:
encoding: UTF-8
string: customer=cus_8Di1wjdVktv5kt
headers:
Accept:
- "*/*; q=0.5, application/xml"
Accept-Encoding:
- gzip, deflate
User-Agent:
- Stripe/v1 RubyBindings/1.30.2
Authorization:
- Bearer sk_test_mGokO9TGtrVxMOyK4yZiktBE
Content-Type:
- application/x-www-form-urlencoded
X-Stripe-Client-User-Agent:
- '{"bindings_version":"1.30.2","lang":"ruby","lang_version":"2.3.0 p0 (2015-12-25)","platform":"x86_64-linux","engine":"ruby","publisher":"stripe","uname":"Linux
version 4.4.0-36-generic (buildd@lcy01-01) (gcc version 5.4.0 20160609 (Ubuntu
5.4.0-6ubuntu1~16.04.2) ) #55-Ubuntu SMP Thu Aug 11 18:01:55 UTC 2016","hostname":"sylvain-sleede-pc"}'
Content-Length:
- '27'
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Thu, 08 Sep 2016 12:45:36 GMT
Content-Type:
- application/json
Content-Length:
- '1925'
Connection:
- keep-alive
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Methods:
- GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Allow-Origin:
- "*"
Access-Control-Max-Age:
- '300'
Cache-Control:
- no-cache, no-store
Request-Id:
- req_99lRjTRT4OH5kv
Stripe-Version:
- '2015-10-16'
Strict-Transport-Security:
- max-age=31556926; includeSubDomains
body:
encoding: UTF-8
string: |
{
"id": "in_18rRuO2sOmf47Nz9qbfxBA0D",
"object": "invoice",
"amount_due": 4590,
"application_fee": null,
"attempt_count": 0,
"attempted": false,
"charge": null,
"closed": false,
"currency": "usd",
"customer": "cus_8Di1wjdVktv5kt",
"date": 1473338736,
"description": null,
"discount": null,
"ending_balance": null,
"forgiven": false,
"lines": {
"object": "list",
"data": [
{
"id": "ii_18rRuK2sOmf47Nz9ye4DQ4PM",
"object": "line_item",
"amount": -510,
"currency": "usd",
"description": "coupon XMAS10",
"discountable": false,
"livemode": false,
"metadata": {},
"period": {
"start": 1473338732,
"end": 1473338732
},
"plan": null,
"proration": false,
"quantity": null,
"subscription": null,
"type": "invoiceitem"
},
{
"id": "ii_18rRuJ2sOmf47Nz9S7f6qfEz",
"object": "line_item",
"amount": 5100,
"currency": "usd",
"description": "Formation Imprimante 3D September 05, 2016 08:00 - 09:00 AM",
"discountable": true,
"livemode": false,
"metadata": {},
"period": {
"start": 1473338731,
"end": 1473338731
},
"plan": null,
"proration": false,
"quantity": null,
"subscription": null,
"type": "invoiceitem"
}
],
"has_more": false,
"total_count": 2,
"url": "/v1/invoices/in_18rRuO2sOmf47Nz9qbfxBA0D/lines"
},
"livemode": false,
"metadata": {},
"next_payment_attempt": 1473342336,
"paid": false,
"period_end": 1473338736,
"period_start": 1473321652,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"subscription": null,
"subtotal": 4590,
"tax": null,
"tax_percent": null,
"total": 4590,
"webhooks_delivered_at": null
}
http_version:
recorded_at: Thu, 08 Sep 2016 12:45:36 GMT
- request:
method: post
uri: https://api.stripe.com/v1/invoices/in_18rRuO2sOmf47Nz9qbfxBA0D/pay
body:
encoding: ASCII-8BIT
string: ''
headers:
Accept:
- "*/*; q=0.5, application/xml"
Accept-Encoding:
- gzip, deflate
User-Agent:
- Stripe/v1 RubyBindings/1.30.2
Authorization:
- Bearer sk_test_mGokO9TGtrVxMOyK4yZiktBE
Content-Type:
- application/x-www-form-urlencoded
X-Stripe-Client-User-Agent:
- '{"bindings_version":"1.30.2","lang":"ruby","lang_version":"2.3.0 p0 (2015-12-25)","platform":"x86_64-linux","engine":"ruby","publisher":"stripe","uname":"Linux
version 4.4.0-36-generic (buildd@lcy01-01) (gcc version 5.4.0 20160609 (Ubuntu
5.4.0-6ubuntu1~16.04.2) ) #55-Ubuntu SMP Thu Aug 11 18:01:55 UTC 2016","hostname":"sylvain-sleede-pc"}'
Content-Length:
- '0'
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Thu, 08 Sep 2016 12:45:37 GMT
Content-Type:
- application/json
Content-Length:
- '1944'
Connection:
- keep-alive
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Methods:
- GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Allow-Origin:
- "*"
Access-Control-Max-Age:
- '300'
Cache-Control:
- no-cache, no-store
Request-Id:
- req_99lRH31egNKaff
Stripe-Version:
- '2015-10-16'
Strict-Transport-Security:
- max-age=31556926; includeSubDomains
body:
encoding: UTF-8
string: |
{
"id": "in_18rRuO2sOmf47Nz9qbfxBA0D",
"object": "invoice",
"amount_due": 4590,
"application_fee": null,
"attempt_count": 1,
"attempted": true,
"charge": "ch_18rRuP2sOmf47Nz9V3NRITbR",
"closed": true,
"currency": "usd",
"customer": "cus_8Di1wjdVktv5kt",
"date": 1473338736,
"description": null,
"discount": null,
"ending_balance": 0,
"forgiven": false,
"lines": {
"object": "list",
"data": [
{
"id": "ii_18rRuK2sOmf47Nz9ye4DQ4PM",
"object": "line_item",
"amount": -510,
"currency": "usd",
"description": "coupon XMAS10",
"discountable": false,
"livemode": false,
"metadata": {},
"period": {
"start": 1473338732,
"end": 1473338732
},
"plan": null,
"proration": false,
"quantity": null,
"subscription": null,
"type": "invoiceitem"
},
{
"id": "ii_18rRuJ2sOmf47Nz9S7f6qfEz",
"object": "line_item",
"amount": 5100,
"currency": "usd",
"description": "Formation Imprimante 3D September 05, 2016 08:00 - 09:00 AM",
"discountable": true,
"livemode": false,
"metadata": {},
"period": {
"start": 1473338731,
"end": 1473338731
},
"plan": null,
"proration": false,
"quantity": null,
"subscription": null,
"type": "invoiceitem"
}
],
"has_more": false,
"total_count": 2,
"url": "/v1/invoices/in_18rRuO2sOmf47Nz9qbfxBA0D/lines"
},
"livemode": false,
"metadata": {},
"next_payment_attempt": null,
"paid": true,
"period_end": 1473338736,
"period_start": 1473321652,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"subscription": null,
"subtotal": 4590,
"tax": null,
"tax_percent": null,
"total": 4590,
"webhooks_delivered_at": 1473338736
}
http_version:
recorded_at: Thu, 08 Sep 2016 12:45:37 GMT
- request:
method: delete
uri: https://api.stripe.com/v1/customers/cus_8Di1wjdVktv5kt/sources/card_18rRuI2sOmf47Nz9TSeEZ96o
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- "*/*; q=0.5, application/xml"
Accept-Encoding:
- gzip, deflate
User-Agent:
- Stripe/v1 RubyBindings/1.30.2
Authorization:
- Bearer sk_test_mGokO9TGtrVxMOyK4yZiktBE
Content-Type:
- application/x-www-form-urlencoded
X-Stripe-Client-User-Agent:
- '{"bindings_version":"1.30.2","lang":"ruby","lang_version":"2.3.0 p0 (2015-12-25)","platform":"x86_64-linux","engine":"ruby","publisher":"stripe","uname":"Linux
version 4.4.0-36-generic (buildd@lcy01-01) (gcc version 5.4.0 20160609 (Ubuntu
5.4.0-6ubuntu1~16.04.2) ) #55-Ubuntu SMP Thu Aug 11 18:01:55 UTC 2016","hostname":"sylvain-sleede-pc"}'
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Thu, 08 Sep 2016 12:45:38 GMT
Content-Type:
- application/json
Content-Length:
- '63'
Connection:
- keep-alive
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Methods:
- GET, POST, HEAD, OPTIONS, DELETE
Access-Control-Allow-Origin:
- "*"
Access-Control-Max-Age:
- '300'
Cache-Control:
- no-cache, no-store
Request-Id:
- req_99lRURlSYOVhs3
Stripe-Version:
- '2015-10-16'
Strict-Transport-Security:
- max-age=31556926; includeSubDomains
body:
encoding: UTF-8
string: |
{
"deleted": true,
"id": "card_18rRuI2sOmf47Nz9TSeEZ96o"
}
http_version:
recorded_at: Thu, 08 Sep 2016 12:45:38 GMT
recorded_with: VCR 3.0.1