Skip to content
This repository has been archived by the owner on Mar 10, 2018. It is now read-only.

Redempted #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ Coupons.apply('invalid', amount: 100.00)
To redeem the coupon you can use `Coupon.redeem`.

```ruby
Coupons.redeem('RAILSCONF15', amount: 600.00)
#=> {:amount => 600.0, :discount => 100.0, :total => 500.0}
options = Coupons.redeem('RAILSCONF15', amount: 600.00)
#=> {:amount => 600.0, :discount => 100.0, :total => 500.0, :redempted_id => 1234}

coupon = Coupons::Models::Coupon.last
Coupons::Models::CouponRedemption.find options[:redempted_id]
# => #<Coupons::Models::CouponRedemption id: 1234, coupon_id: 1, user_id: nil, order_id: nil, created_at: "2016-05-03 13:05:51", updated_at: "2016-05-03 13:05:51">

coupon.redemptions_count
#=> 1
Expand Down
126 changes: 126 additions & 0 deletions config/locale/it.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
it:
date:
formats:
coupon: '%b %d, %Y'

page_meta:
titles:
base: "%{value}"
coupons:
coupons:
index: Coupons
new: Nuovo Coupon
edit: Modifica Coupon
remove: Elimina Coupon
duplicate: Duplica Coupon

views:
pagination:
first: "&laquo; Primo"
last: "Ultimo &raquo;"
previous: "&lsaquo; Precedente"
next: "Successivo &rsaquo;"
truncate: "&hellip;"

paginate:
previous: 'Pagina precedente'
next: 'Pagina Successiva'
page: 'Pagina %{page}'

coupons:
new_coupon_button: 'Crea Coupon'
are_you_sure_you_want_to_remove_html: >
Sei sicuro di voler rimuovere questo coupon?
you_cant_undo_removal_html: >
All redemption trackings will be removed as well.
<strong>You won't be able to undo this action.</strong>

blank_slate:
no_coupons: Nessun Coupons
no_coupons_description: Non hai ancora creato nessun coupon. Qui é dove appariranno.

selected_rules:
one: '${count} coupon selezionato'
other: '${count} coupons selezionati'

'off':
amount_html: '<span class="amount">$%{amount} OFF</span>'
percentage_html: '<span class="percentage">%{amount}% OFF</span>'

redeemed_html:
zero: <span class="mute">Non ancora</span>
one: '%{count}/<span class="limit">%{limit}</span>'
other: '%{count}/<span class="limit">%{limit}</span>'

limit_html:
zero: '<span class="infinite">∞</span>'
one: '%{count}'
other: '%{count}'

columns:
description: 'Descrizione'
discount: 'Sconto'
redeemed: 'Riscattato'
expiration: 'Scadenza'

actions:
edit: 'Modifica'
remove: 'Elimina'
confirm: "Sì, sono sicuro!"
cancel: 'No'
go_back: 'Indietro'
duplicate: 'Duplica'

flash:
coupons:
create:
notice: Il coupon è stato creato!
update:
notice: Il coupon è stato aggiornato!
destroy:
notice: Il coupon è stato rimosso!
batch:
invalid_action: 'Questa azione non è valida!'
removal:
notice: 'I coupon sono stati rimossi'

labels:
coupon:
description: 'Descrizione'
redemption_limit: 'Limite riscatti'
type: 'Tipo'
amount: 'Prezzo'
code: 'Codice sconto'
valid_from: 'Valido dal'
valid_until: 'Valido fino al'

hints:
coupon:
type: 'Seleziona come dovrà funzionare lo sconto.'
code: 'Il cliente dovrà fornire questo codice.'
description: 'Descrivi questo coupon così ricorderai a cosa serve'
redemption_limit: 'Setta quante volte il coupon può essere usato. Inserisci zero per infinito'
amount: 'Questo é lo sconto. 0-100 per lo sconto percentuale, zero o numero positivo per sconto fisso.'
valid_from: 'Da quando il coupon sará disponibile.'
valid_until: 'Data di scadenza coupon. Per default senza scadenza.'

form_error_description: 'Ci sono errori nel form:'

coupon:
type:
amount: 'Prezzo ($)'
percentage: 'Percentuale (%)'

buttons:
create: 'Crea Coupon'
edit: 'Aggiorna Coupon'
remove_selected: 'Rimuovi Coupons'

no_description: 'Nessuna descrizione'
dont_expire: Mai

activerecord:
errors:
messages:
coupon_already_expired: Deve essere uguale o maggiore di oggi
coupon_valid_until: Deve essere maggiore o uguale alla data di inizio validità.
3 changes: 2 additions & 1 deletion lib/coupons/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def redeem(code, options)
coupon = find(code, options)
return options unless coupon

coupon.redemptions.create!(options.slice(:user_id, :order_id))
redempted = coupon.redemptions.create!(options.slice(:user_id, :order_id))
options.merge!(redempted_id: redempted.id)
coupon.apply(options)
end

Expand Down
3 changes: 2 additions & 1 deletion lib/coupons/models/coupon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ def expired?
valid_until && valid_until <= Date.current
end

# without redemption limit OR redeemed count less than redemption limit
def has_available_redemptions?
redemptions_count.zero? || redemptions_count < redemption_limit
redemption_limit.zero? || redemptions_count < redemption_limit
end

def started?
Expand Down
6 changes: 6 additions & 0 deletions spec/coupons/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,10 @@
maker.redeem(coupon.code, order_id: 1234)
expect(coupon.redemptions.last.order_id).to eq('1234')
end

it 'return coupon redemption id' do
coupon = maker.create(amount: 10, type: 'amount')
options = maker.redeem(coupon.code, order_id: 1234)
expect(coupon.redemptions.last.id).to eq(options[:redempted_id])
end
end