# show the valid IAPR records for the parent
parent = Parent.find(…)
pp InAppPurchaseReceipt.where(parent: parent).where.not(blob: nil); nil
# show the receipts from an Apple call by product
blob = InAppPurchaseReceipt.where(parent: parent).where.not(blob: nil).first.blob
pp TabletApi::Service::VerifyAppleReceipt.call(blob).first.group_by(&:product_id); nil
# find the blob we've logged for the parent (local PC)
cd ~Blake/readingeggs
bx grep-log --grep-opts="-A 5 -B 1" "'parent.id: 4053044'"
# does the parent account still need IAPR 'migration'?
TabletApi::Policy::Migration.allowed?(parent.id, blob)
# does the student_subscription point to a different blob?
student = Student.find(…)
StudentSubscription.
where(student: student).
joins(:in_app_purchase_receipts).
where.not(in_app_purchase_receipts: {blob: nil}).
map { |ss| ss.in_app_purchase_receipts }.
flatten.
uniq
# find errors in production logs:
bx grep-log "'PurchasesController\\.update_all.*failure'"
# recreate the InAppPurchaseReceipt record for the parent based on the blob
parent = Parent.find(…)
TabletApi::Workflow::Migration::ConvertIAPRData.call(parent, blob, success: success, failure: failure)
# create any missing student_subscriptions for the parent's children
parent = Parent.find(…)
success = -> { puts "success" }
failure = ->(error) { puts "failure: #{error}" }
TabletApi::Workflow::Renewal::Parent::CreateSubscription.call(parent, success: success, failure: failure)
# manually change the IAPR record student_subscriptions
# and create the missing subs
student_sub_ids = […, …]
good_iapr = StudentSubscription.find(…).in_app_purchase_receipts.first
success = -> { puts "success" }
failure = ->(error) { puts "failure: #{error}" }
StudentSubscription.where(id: student_sub_ids).each do |ss|
ss.in_app_purchase_receipts.clear << good_iapr
ss.save!
TabletApi::Workflow::Renewal::Student::CreateSubscription.call(ss, good_iapr, success: success, failure: failure)
end
#
# manually create a missing subscription record for a student
# - the Apple response to the verify(blob) says the student should have subs
# - but we have no tablet student_subscription records for the student
#
success = -> { puts "success" }
failure = ->(error) { puts "failure: #{error}" }
product = 'Tablet_Monthly_RE_Combined_Maths_1st_Prod'
blob = '…'
parent = Parent.find(…)
student = Student.find(…)
transaction_id = '190000394915509'
::TabletApi::Workflow::Purchase::CreateSubscription.call(
parent_id: parent.id,
apple_product_title: product,
student_info: {id: student.id, first_name: student.first_name, year_of_birth: student.year_of_birth},
transaction_id: transaction_id,
original_transaction_id: transaction_id,
receipt_blob: blob,
currency_id: parent.currency.id,
success: success,
failure: failure
)
# then manually change the start_date/end_date to match the Apple response...
apple_receipt = TabletApi::Service::VerifyAppleReceipt.call(blob).first.select { |x| x.product_id == product }.sort_by(&:purchased_at).first
student.student_subscriptions.select { |x| x.subscription.name =~ /#{product}/ }.each { |y| y.update!(start_date: apple_receipt.purchased_at.utc.beginning_of_day, end_date: apple_receipt.expires_at.utc.beginning_of_day) }
# if some of many students are no longer subscribers, need to exclude them by hand and renew by student_sub
parent = Parent.find(…)
success = -> { puts "success" }
failure = ->(error) { puts "failure: #{error}" }
TabletApi::Query::Renewal::StudentSubs.for_parent(parent.id).
reject { |sub_and_iapr| sub_and_iapr[:student_sub].student_id == … }.
each do |sub_and_iapr|
TabletApi::Workflow::Renewal::Student::CreateSubscription.call(
sub_and_iapr[:student_sub],
sub_and_iapr[:iapr],
success: success,
failure: failure
)
end