examples/utils.rb in voucherify-0.8.0 vs examples/utils.rb in voucherify-0.8.2

- old
+ new

@@ -1,21 +1,73 @@ -require 'voucherify/utils' +require '../lib/voucherify/utils' include Utils -discount = Utils.calculate_discount(20, { +base_price = 20.00 + +puts "base price: " + base_price.to_s + +puts "===== amount discount =====" +amount_voucher = { discount: { - unit_off: 2.0, - type: 'UNIT' + amount_off: 1000, # 10.0 + type: 'AMOUNT' } -}, 5) +} +puts "discount: " + Utils.calculate_discount(base_price, amount_voucher).to_s +puts "price after discount: " + Utils.calculate_price(base_price, amount_voucher).to_s +puts -print(discount) -discount = Utils.calculate_price(20, amount_voucher_object = { +puts "===== percent discount ====" + +percent_discount_voucher = { discount: { - amount_off: 7.0, - type: 'AMOUNT' + percent_off: 20, + type: 'PERCENT' } -}) +} -print(discount) +puts "discount: " + Utils.calculate_discount(base_price, percent_discount_voucher).to_s +puts "price after discount: " + Utils.calculate_price(base_price, percent_discount_voucher).to_s +puts + + +puts "===== unit discount =======" + +unit_discount_voucher = { + discount: { + unit_off: 2, + type: 'UNIT' + } +} + +puts "discount: " + Utils.calculate_discount(base_price, unit_discount_voucher, 5).to_s +puts "price after discount: " + Utils.calculate_price(base_price, unit_discount_voucher, 5).to_s +puts + + +puts "===== gift voucher ========" + +gift_voucher = { + gift: { + amount: 1000, + balance: 500 + } +} + +puts "discount: " + Utils.calculate_discount(base_price, gift_voucher).to_s +puts "price after discount: " + Utils.calculate_price(base_price, gift_voucher).to_s +puts + +puts "===== gift voucher 2 ======" + +gift_voucher2 = { + gift: { + amount: 10000, + balance: 5000 + } +} + +puts "discount: " + Utils.calculate_discount(base_price, gift_voucher2).to_s +puts "price after discount: " + Utils.calculate_price(base_price, gift_voucher2).to_s +puts \ No newline at end of file