* api for marking purchase from ios
This commit is contained in:
parent
5e754a7096
commit
6d514c3df2
|
|
@ -92,6 +92,12 @@ module JamRuby
|
|||
line_items
|
||||
end
|
||||
|
||||
def self.ios_purchase(current_user, jam_track, receipt)
|
||||
jam_track_right = JamRuby::JamTrackRight.find_or_create_by_user_id_and_jam_track_id(current_user.id, jam_track.id) do |jam_track_right|
|
||||
jam_track_right.redeemed = false
|
||||
end
|
||||
end
|
||||
|
||||
# place_order will create one or more sales based on the contents of shopping_carts for the current user
|
||||
# individual subscriptions will end up create their own sale (you can't have N subscriptions in one sale--recurly limitation)
|
||||
# jamtracks however can be piled onto the same sale as adjustments (VRFS-3028)
|
||||
|
|
|
|||
|
|
@ -253,6 +253,25 @@ class ApiJamTracksController < ApiController
|
|||
puts "jamtrack_mixdowns #{jamtrack_mixdowns}"
|
||||
end
|
||||
|
||||
def ios_order_placed
|
||||
jam_track = JamTrack.find(params[:jam_track_id])
|
||||
|
||||
sales = Sale.ios_purchase(current_user, jam_track, nil)
|
||||
|
||||
#
|
||||
# sales.each do |sale|
|
||||
# if sale.is_jam_track_sale?
|
||||
# sale.sale_line_items.each do |line_item|
|
||||
# jam_track = line_item.product
|
||||
# jam_track_right = jam_track.right_for_user(current_user)
|
||||
# response[:jam_tracks] << {name: jam_track.name, id: jam_track.id, jam_track_right_id: jam_track_right.id, version: jam_track.version}
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
response = {name: jam_track.name, id: jam_track.id, jam_track_right_id: jam_track.right_for_user(current_user).id, version: jam_track.version}
|
||||
render :json => response, :status => 200
|
||||
end
|
||||
|
||||
private
|
||||
def lookup_jam_track_right
|
||||
@jam_track_right = JamTrackRight.where("jam_track_id=? AND user_id=?", params[:id], current_user.id).first
|
||||
|
|
|
|||
|
|
@ -327,6 +327,7 @@ SampleApp::Application.routes.draw do
|
|||
match '/recurly/billing_info' => 'api_recurly#billing_info', :via => :get
|
||||
match '/recurly/update_billing_info' => 'api_recurly#update_billing_info', :via => :put
|
||||
match '/recurly/place_order' => 'api_recurly#place_order', :via => :post
|
||||
match '/ios/order_placed' => 'api_jam_tracks#ios_order_placed', :via => :post
|
||||
|
||||
# sale info
|
||||
match '/payment_histories' => 'api_payment_histories#index', :via => :get
|
||||
|
|
|
|||
|
|
@ -26,6 +26,16 @@ describe ApiJamTracksController do
|
|||
controller.current_user = @user
|
||||
end
|
||||
|
||||
describe "ios_order_placed" do
|
||||
it "succeeds" do
|
||||
post :ios_order_placed, { jam_track_id: @jam_track.id }
|
||||
|
||||
response.status.should == 200
|
||||
right = @jam_track.right_for_user(@user)
|
||||
right.id.should eq(JSON.parse(response.body)["jam_track_right_id"])
|
||||
end
|
||||
end
|
||||
|
||||
describe "admin" do
|
||||
before(:each) do
|
||||
@admin = FactoryGirl.create(:admin)
|
||||
|
|
|
|||
Loading…
Reference in New Issue