Skip to content

Commit

Permalink
Merge branch 'dev' for release 2.5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
jarod022 committed Jun 8, 2017
2 parents 0a76aec + 6d05765 commit 36a8657
Show file tree
Hide file tree
Showing 12 changed files with 2,332 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .fabmanager-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.6
2.5.7
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog Fab Manager

## v2.5.7 2017 June 8

- Portuguese and Brazilian support
- Fix a bug: reservation amount total isnt equal stripe invoice amount that be paid by customer

## v2.5.6 2017 May 18

- Ability for admins to create users as organizations
Expand Down
3 changes: 3 additions & 0 deletions app/exceptions/invoice_total_diffrent_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Raised when total of reservation isnt equal total of strip's invoice
class InvoiceTotalDiffrentError < StandardError
end
62 changes: 50 additions & 12 deletions app/models/reservation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,15 @@ def generate_invoice_items(on_site = false, coupon_code = nil)
end

def save_with_payment(coupon_code = nil)
build_invoice(user: user)
invoice_items = generate_invoice_items(false, coupon_code)
begin
clean_pending_strip_invoice_items
build_invoice(user: user)
invoice_items = generate_invoice_items(false, coupon_code)
rescue => e
logger.error e
errors[:payment] << e.message
return false
end
if valid?
# TODO: refactoring
customer = Stripe::Customer.retrieve(user.stp_customer_id)
Expand Down Expand Up @@ -249,46 +256,52 @@ def save_with_payment(coupon_code = nil)
stp_invoice = Stripe::Invoice.create(
customer: user.stp_customer_id,
)
# cf: https://board.sleede.com/project/sleede-fab-manager/issue/77
# this function only check reservation total is equal strip invoice total when
# pay only reservation not reservation + subscription
#if !is_equal_reservation_total_and_stp_invoice_total(stp_invoice, coupon_code)
#raise InvoiceTotalDiffrentError
#end
stp_invoice.pay
card.delete if card
self.stp_invoice_id = stp_invoice.id
self.invoice.stp_invoice_id = stp_invoice.id
set_total_and_coupon(coupon_code)
save!
rescue Stripe::CardError => card_error
clear_payment_info(card, stp_invoice, invoice_items)
clear_payment_info(card, stp_invoice)
logger.info card_error
errors[:card] << card_error.message
return false
rescue Stripe::InvalidRequestError => e
# Invalid parameters were supplied to Stripe's API
clear_payment_info(card, stp_invoice, invoice_items)
clear_payment_info(card, stp_invoice)
logger.error e
errors[:payment] << e.message
return false
rescue Stripe::AuthenticationError => e
# Authentication with Stripe's API failed
# (maybe you changed API keys recently)
clear_payment_info(card, stp_invoice, invoice_items)
clear_payment_info(card, stp_invoice)
logger.error e
errors[:payment] << e.message
return false
rescue Stripe::APIConnectionError => e
# Network communication with Stripe failed
clear_payment_info(card, stp_invoice, invoice_items)
clear_payment_info(card, stp_invoice)
logger.error e
errors[:payment] << e.message
return false
rescue Stripe::StripeError => e
# Display a very generic error to the user, and maybe send
# yourself an email
clear_payment_info(card, stp_invoice, invoice_items)
clear_payment_info(card, stp_invoice)
logger.error e
errors[:payment] << e.message
return false
rescue => e
# Something else happened, completely unrelated to Stripe
clear_payment_info(card, stp_invoice, invoice_items)
clear_payment_info(card, stp_invoice)
logger.error e
errors[:payment] << e.message
return false
Expand All @@ -300,16 +313,21 @@ def save_with_payment(coupon_code = nil)
end
end

def clear_payment_info(card, invoice, invoice_items)
# check reservation amount total and strip invoice total to pay is equal
# @params stp_invoice[Stripe::Invoice]
# @params coupon_code[String]
# return Boolean
def is_equal_reservation_total_and_stp_invoice_total(stp_invoice, coupon_code = nil)
compute_amount_total_to_pay(coupon_code) == stp_invoice.total
end

def clear_payment_info(card, invoice)
begin
card.delete if card
if invoice
invoice.closed = true
invoice.save
end
if invoice_items.size > 0
invoice_items.each(&:delete)
end
rescue Stripe::InvalidRequestError => e
logger.error e
rescue Stripe::AuthenticationError => e
Expand All @@ -323,6 +341,12 @@ def clear_payment_info(card, invoice, invoice_items)
end
end

def clean_pending_strip_invoice_items
pending_invoice_items = Stripe::InvoiceItem.list(customer: user.stp_customer_id, limit: 100).data.select { |ii| ii.invoice.nil? }
pending_invoice_items.each do |ii|
ii.delete
end
end

def save_with_local_payment(coupon_code = nil)
if user.invoicing_disabled?
Expand Down Expand Up @@ -463,6 +487,20 @@ def debit_user_wallet
end
end

# this function only use for compute total of reservation before save
def compute_amount_total_to_pay(coupon_code = nil)
total = invoice.invoice_items.map(&:amount).map(&:to_i).reduce(:+)
unless coupon_code.nil?
cp = Coupon.find_by(code: coupon_code)
if not cp.nil? and cp.status(user.id) == 'active'
total = CouponService.new.apply(total, cp, user.id)
else
raise InvalidCouponError
end
end
return total - get_wallet_amount_debit
end

##
# Set the total price to the reservation's invoice, summing its whole items.
# Additionally a coupon may be applied to this invoice to make a discount on the total price
Expand Down
138 changes: 69 additions & 69 deletions config/application.yml.default
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
# Add application configuration variables here, as shown below.

POSTGRES_HOST: localhost
POSTGRES_PASSWORD:
REDIS_HOST: localhost
ELASTICSEARCH_HOST: localhost

SECRET_KEY_BASE: 83daf5e7b80d990f037407bab78dff9904aaf3c195a50f84fa8695a22287e707dfbd9524b403b1dcf116ae1d8c06844c3d7ed942564e5b46be6ae3ead93a9d30
STRIPE_API_KEY:
STRIPE_PUBLISHABLE_KEY:
STRIPE_CURRENCY: 'eur'

INVOICE_PREFIX: Demo-FabLab-facture
FABLAB_WITHOUT_PLANS: 'false'
FABLAB_WITHOUT_SPACES: 'true'

DEFAULT_MAIL_FROM: Fab Manager Demo <[email protected]>

# For prod & staging env only
DEFAULT_HOST: fab-manager.com
DEFAULT_PROTOCOL: https
DELIVERY_METHOD: smtp
SMTP_ADDRESS:
SMTP_PORT: '587'
SMTP_USER_NAME:
SMTP_PASSWORD:
GA_ID: ''
##

ADMIN_EMAIL: '[email protected]'
ADMIN_PASSWORD: 'adminadmin'

DISQUS_SHORTNAME:

TWITTER_NAME: 'FablabGrenoble'
TWITTER_CONSUMER_KEY: ''
TWITTER_CONSUMER_SECRET: ''
TWITTER_ACCESS_TOKEN: ''
TWITTER_ACCESS_TOKEN_SECRET: ''

FACEBOOK_APP_ID: ''

RAILS_LOCALE: 'fr'
APP_LOCALE: 'fr'
MOMENT_LOCALE: 'fr'
SUMMERNOTE_LOCALE: 'fr-FR'
ANGULAR_LOCALE: 'fr-fr'
MESSAGEFORMAT_LOCALE: 'fr'
FULLCALENDAR_LOCALE: 'fr'

ELASTICSEARCH_LANGUAGE_ANALYZER: 'french'

TIME_ZONE: 'Paris'
WEEK_STARTING_DAY: 'monday'
D3_DATE_FORMAT: '%d/%m/%y'
UIB_DATE_FORMAT: 'dd/MM/yyyy'
EXCEL_DATE_FORMAT: 'dd/mm/yyyy'

OPENLAB_APP_SECRET:
OPENLAB_APP_ID:
OPENLAB_BASE_URI: 'https://openprojects.fab-manager.com'

LOG_LEVEL: 'debug'

ALLOWED_EXTENSIONS: pdf ai eps cad math svg stl dxf dwg obj step iges igs 3dm 3dmf doc docx png ino scad fcad skp sldprt sldasm slddrw slddrt tex latex ps
ALLOWED_MIME_TYPES: application/pdf application/postscript application/illustrator image/x-eps image/svg+xml application/sla application/dxf application/acad application/dwg application/octet-stream application/step application/iges model/iges x-world/x-3dmf application/vnd.openxmlformats-officedocument.wordprocessingml.document image/png text/x-arduino text/plain application/scad application/vnd.sketchup.skp application/x-koan application/vnd-koan koan/x-skm application/vnd.koan application/x-tex application/x-latex

# 10485760 = 10 megabytes
MAX_IMAGE_SIZE: '10485760'
-# Add application configuration variables here, as shown below.
-
-POSTGRES_HOST: localhost
-POSTGRES_PASSWORD:
-REDIS_HOST: localhost
-ELASTICSEARCH_HOST: localhost
-
-SECRET_KEY_BASE: 83daf5e7b80d990f037407bab78dff9904aaf3c195a50f84fa8695a22287e707dfbd9524b403b1dcf116ae1d8c06844c3d7ed942564e5b46be6ae3ead93a9d30
-STRIPE_API_KEY:
-STRIPE_PUBLISHABLE_KEY:
-STRIPE_CURRENCY: 'eur'
-
-INVOICE_PREFIX: Demo-FabLab-facture
-FABLAB_WITHOUT_PLANS: 'false'
-FABLAB_WITHOUT_SPACES: 'true'
-
-DEFAULT_MAIL_FROM: Fab Manager Demo <[email protected]>
-
-# For prod & staging env only
-DEFAULT_HOST: fab-manager.com
-DEFAULT_PROTOCOL: https
-DELIVERY_METHOD: smtp
-SMTP_ADDRESS:
-SMTP_PORT: '587'
-SMTP_USER_NAME:
-SMTP_PASSWORD:
-GA_ID: ''
-##
-
-ADMIN_EMAIL: '[email protected]'
-ADMIN_PASSWORD: 'adminadmin'
-
-DISQUS_SHORTNAME:
-
-TWITTER_NAME: 'FablabGrenoble'
-TWITTER_CONSUMER_KEY: ''
-TWITTER_CONSUMER_SECRET: ''
-TWITTER_ACCESS_TOKEN: ''
-TWITTER_ACCESS_TOKEN_SECRET: ''
-
-FACEBOOK_APP_ID: ''
-
-RAILS_LOCALE: 'fr'
-APP_LOCALE: 'fr'
-MOMENT_LOCALE: 'fr'
-SUMMERNOTE_LOCALE: 'fr-FR'
-ANGULAR_LOCALE: 'fr-fr'
-MESSAGEFORMAT_LOCALE: 'fr'
-FULLCALENDAR_LOCALE: 'fr'
-
-ELASTICSEARCH_LANGUAGE_ANALYZER: 'french'
-
-TIME_ZONE: 'Paris'
-WEEK_STARTING_DAY: 'monday'
-D3_DATE_FORMAT: '%d/%m/%y'
-UIB_DATE_FORMAT: 'dd/MM/yyyy'
-EXCEL_DATE_FORMAT: 'dd/mm/yyyy'
-
-OPENLAB_APP_SECRET:
-OPENLAB_APP_ID:
-OPENLAB_BASE_URI: 'https://openprojects.fab-manager.com'
-
-LOG_LEVEL: 'debug'
-
-ALLOWED_EXTENSIONS: pdf ai eps cad math svg stl dxf dwg obj step iges igs 3dm 3dmf doc docx png ino scad fcad skp sldprt sldasm slddrw slddrt tex latex ps
-ALLOWED_MIME_TYPES: application/pdf application/postscript application/illustrator image/x-eps image/svg+xml application/sla application/dxf application/acad application/dwg application/octet-stream application/step application/iges model/iges x-world/x-3dmf application/vnd.openxmlformats-officedocument.wordprocessingml.document image/png text/x-arduino text/plain application/scad application/vnd.sketchup.skp application/x-koan application/vnd-koan koan/x-skm application/vnd.koan application/x-tex application/x-latex
-
-# 10485760 = 10 megabytes
-MAX_IMAGE_SIZE: '10485760'
Loading

0 comments on commit 36a8657

Please sign in to comment.