Sha256: b94cfe5a057edc80c0b03b4ab773ab89b0127fdcb2c6e0000c4c61de5fc38795
Contents?: true
Size: 1.48 KB
Versions: 1
Compression:
Stored size: 1.48 KB
Contents
require 'rack' require 'rack/contrib' require 'sinatra/base' require 'sinatra/param' require 'rack' require 'sequel' require 'venice' module Rack class InAppPurchase < Sinatra::Base use Rack::PostBodyContentTypeParser helpers Sinatra::Param autoload :Product, 'rack/in-app-purchase/models/product' autoload :Receipt, 'rack/in-app-purchase/models/receipt' disable :raise_errors, :show_exceptions configure do Sequel.extension :core_extensions, :migration if ENV['DATABASE_URL'] DB = Sequel.connect(ENV['DATABASE_URL']) Sequel::Migrator.run(DB, ::File.join(::File.dirname(__FILE__), "in-app-purchase/migrations"), table: 'in_app_purchase_schema_info') end end before do content_type :json end get '/products/identifiers' do Product.where(is_enabled: true).map(:product_identifier).to_json end post '/receipts/verify' do param :'receipt-data', String, required: true status 203 begin receipt = Venice::Receipt.verify!(params[:'receipt-data']) Receipt.create({ip_address: request.ip}.merge(receipt.to_h)) content = settings.content_callback.call(receipt) rescue nil { status: 0, receipt: receipt.to_h, content: content }.select{|k,v| v}.to_json rescue Venice::Receipt::VerificationError => error { status: error.message }.to_json rescue halt 500 end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rack-in-app-purchase-0.1.1 | ./lib/rack/in-app-purchase.rb |