Closed matthijsvdr closed 11 years ago
you have 2 endpoints: 1) issuing passes something like this
post "/v1/passes/get_ticket" => "Passbook::passes#get_pkpass", :defaults => { :pass_type_id => 'pass.company.ticket' }
2) getting pkpass based on serial number (this one is in the gem)
which one are you calling?
if its 1), then the likelihood is that your problem is in the model you created for the pass make sure you have something like
before_create :set_pass_fields
def set_pass_fields
self.authentication_token = Base64.urlsafe_encode64(SecureRandom.base64(36))
self.serial_number = Base64.urlsafe_encode64(SecureRandom.base64(36))
end
def self.update_or_create params
...
def update_pass pkpass
update_json pkpass.json
end
def update_json pass_json
pass_json['authenticationToken'] = authentication_token
pass_json['serialNumber'] = serial_number
...
the model looks like that, i only changed the update_json with an extra value, everything else in there is the default. When i open the url localhost:3000/v1/passes/card (card is my model name) i always get the same pass with the same authentication_token and serial_number.
Isn't it suppose to change ever time its called? and create a new pass with a differed authentication_token and serial_number?
class Card < ActiveRecord::Base
attr_protected :serial_number, :authentication_token
attr_accessible :card_id
before_create :set_pass_fields
def set_pass_fields
self.authentication_token = Base64.urlsafe_encode64(SecureRandom.base64(36))
self.serial_number||= Base64.urlsafe_encode64(SecureRandom.base64(36))
end
def self.update_or_create params
card_pass = find_by_card_id params[:card_id]
card_pass ||=new
params.slice(*attr_accessible[:default].map(&:to_sym)).each do |attr, val|
card_pass.send :"#{attr}=", val
end
card_pass.save!
card_pass
end
def check_for_updates
end
def update_pass pkpass
update_json pkpass.json
end
def update_json pass_json
puts authentication_token
puts serial_number
pass_json['authenticationToken'] = authentication_token
pass_json['serialNumber'] = serial_number
#don't forget to change the URL to whatever address your server is at
pass_json['webServiceURL'] = "http://10.10.4.127:3000"
#add more customization to your passbook's JSON right here
storeCard = pass_json['storeCard']
auxFields = storeCard['auxiliaryFields']
auxFields[1]['value'] = DateTime.now + 12.month
end
end
Do you do a
POST localhost:3000/v1/passes/card
and then pass card_id in your payload?
paste in the line from your routes.rb for that endpoint
tnx :)
glad it worked :)
Found the gem on google, and tryed it out.
But when i create a the first pass everything works fine. But the second pass from the same template generates the same serial number and auth token? Also in the sqlite database only one pass shows up, with one registration.
Is this the correct behaviour? Or is something going wrong?