Class: Pindo::Command::Deploy::Iap

Inherits:
Pindo::Command::Deploy show all
Includes:
AppStoreInAppPurchase, Pindo::Command::DeployOptions
Defined in:
lib/pindo/command/deploy/iap.rb

Constant Summary

Constants inherited from Pindo::Command

Pindo::Command::DEFAULT_OPTIONS, Pindo::Command::DEFAULT_ROOT_OPTIONS

Instance Attribute Summary

Attributes included from Pindo::Command::DeployOptions

#additional_args, #apple_id, #args_adhoc_flag, #args_appconfig, #args_appconfig_dir, #args_appconfig_fullname, #args_apple_id, #args_appstore_flag, #args_array, #args_bundle_id, #args_dev_flag, #args_repo_name, #argv_temp, #bundle_id, #bundle_id_extension, #bundle_id_extensionad, #bundle_id_extensionporn, #bundle_id_imessage, #bundle_id_keyboard, #bundle_id_pushcontent, #bundle_id_pushservice, #bundle_id_siri, #bundle_id_siriui, #bundle_id_watchapp, #bundle_id_watchapp_extension, #bundle_id_widget, #config_json, #deploy_acount_id, #deploy_group_id, #deploy_icloud_id, #deploy_identifier, #deploy_identifier_extension, #deploy_identifier_extensionad, #deploy_identifier_extensionporn, #deploy_identifier_imessage, #deploy_identifier_keyboard, #deploy_identifier_pushcontent, #deploy_identifier_pushservice, #deploy_identifier_siri, #deploy_identifier_siriui, #deploy_identifier_watchapp, #deploy_identifier_watchapp_extension, #deploy_identifier_widget, #deploy_repo_name, #group_id, #icloud_id, #newconfuse_flag, #oldconfuse_flag

Attributes inherited from Pindo::Command

#args_help_flag

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AppStoreInAppPurchase

#create_consumable_iap_items, #create_purchase_item, #create_purchase_item_localization, #create_purchase_item_price, #create_subscription_group_item, #create_subscription_group_localization, #create_subscription_item, #create_subscription_item_introductory_offer, #create_subscription_item_introductory_offer_with_singlefunc, #create_subscription_item_localization, #create_subscription_item_price, #create_subscription_item_price_with_singlefunc, #create_subscription_item_territory_availability, #create_subscription_items, #create_subscriptions_groups, #delete_subscription_item_introductory_offer, #delete_subscription_item_introductory_offer_with_singlefunc, #get_app_share_secrets, #get_consumable_iap_items, #get_price_tier_dict, #get_purchase_item_price, #get_subscription_item_price, #get_subscription_items, #get_subscriptions_groups, #update_purchase_item_name, #update_purchase_item_territory_availability, #update_subscription_item_attributes, #update_subscription_item_introductory_offer, #update_subscription_item_period, #update_subscription_item_screenshots, #upload_purchase_item_screenshots

Methods included from Pindo::Command::DeployOptions

#check_config_version, #get_build_type_args, #get_bundle_id_map, #get_confuse_type_args, #init_deploy_params, #init_develop_params, #print_params_info

Methods inherited from Pindo::Command

run

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Methods included from Githelper

#add_branch, #add_tag, #add_tag_with_check, #clone_clang_repo, #clone_devclang_repo, #clone_pindo_common_config_repo, #clone_pindo_env_config_repo, #clong_buildconfig_repo, #get_repo_base_name, #getcode_to_dir, #git_addpush_repo, #git_latest_commit_id, #local_branch_exists?, #local_tag_exists?, #prepare_gitenv, #process_need_add_files, #remote_branch_exists?, #remote_tag_exists?, #remove_branch, #remove_tag

Methods included from Executable

capture_command, #executable, execute_command, which, which!

Constructor Details

#initialize(argv) ⇒ Iap

Returns a new instance of Iap.



47
48
49
50
51
52
53
54
# File 'lib/pindo/command/deploy/iap.rb', line 47

def initialize(argv)

  @check_flag = argv.flag?('check', false)
  @download_flag = argv.flag?('download', false)
  @boss_flag = argv.flag?('boss', false)

  super
end

Class Method Details

.optionsObject



25
26
27
28
29
30
31
32
33
# File 'lib/pindo/command/deploy/iap.rb', line 25

def self.options
  [

    ['--check', '检查iap信息'],
    ['--download', '从appstore下载app的iap信息,用法: pindo deploy iap --download'],
    ['--boss', '生成boss的iap信息, 用法: pindo deploy iap --boss'],

  ].concat(super)
end

Instance Method Details

#check_purchase_items_right(in_app_purchase_json: nil, config_json: nil) ⇒ Object



396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/pindo/command/deploy/iap.rb', line 396

def check_purchase_items_right(in_app_purchase_json:nil, config_json:nil)

    puts
    puts "检查iap 配置"
    puts
    app_version = @config_json["app_info"]["app_version"]
    bundle_id = @bundle_id
    platform = @config_json["app_setting"]["kGUKeyAppPlatform"] || @config_json["app_setting"]["app_platform"]
    app_type = @config_json["project_info"]["app_type"]

    boss_client = BossClient.new(app_type:app_type, is_dev:false)
    data_json =  Pindo::Command::Utils::Boss::get_config(boss_client:boss_client, app_version:app_version, bundle_id:bundle_id, platform:platform)

    # if !data_json["data"].nil?
    #     puts JSON.pretty_generate(data_json["data"])
    # else
    #     puts JSON.pretty_generate(data_json)
    # end

    gate_vip_items = get_gate_vip_items(app_type:app_type, boss_config:data_json["data"])

    if !gate_vip_items.nil? && gate_vip_items.size > 0
        itc_vip_items = []
        in_app_purchase_json["auto_renew"].each do |group_item|
            items = group_item["subscription_items"] || []
            itc_vip_items += items
            items = group_item["items"] || []
            itc_vip_items += items
        end


        gate_vip_items.each do |offer_id, boss_iap_item|
            boss_product_id = boss_iap_item["iap"]["product_id"]
            boss_price = boss_iap_item["iap"]["price"]
            free_days = boss_iap_item["free_days"]

            itc_vip_item = itc_vip_items.find { |item| item["product_id"].eql?(boss_product_id)}
            if !itc_vip_item.nil?
              puts "product id: #{boss_product_id} 与boss一致!"

              if boss_price.eql?("$"+itc_vip_item["price"].to_s)
                  puts "    价格一致!  价格:#{boss_price}"
              else
                  local_price = itc_vip_item["price"].to_s
                  raise Informative, "    价格不一致 Boss:#{boss_price}, Local:$#{local_price}"
              end

              if !itc_vip_item["subscription_free_trial"].nil? && !free_days.nil? && itc_vip_item["subscription_free_trial"].to_s.eql?(free_days.to_s + "d")
                  puts "    有三天试用, 一致!"
              elsif itc_vip_item["subscription_free_trial"].nil? && free_days.nil?
                puts "    无三天试用, 一致!"
              else
                raise Informative,  "    三天试用不一致!"
              end


            else
              raise Informative, "product id: #{boss_product_id} 与boss不匹配!"
            end
        end
    end

    offer_vip_items = get_gate_vip_items(app_type:app_type, boss_config:data_json["data"])
end

#create_appstore_iap(appstore_iap_file: nil) ⇒ Object



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/pindo/command/deploy/iap.rb', line 289

def create_appstore_iap(appstore_iap_file:nil)

  temp_iap_json = JSON.parse(File.read(appstore_iap_file))

  if @check_flag
      check_purchase_items_right(in_app_purchase_json:temp_iap_json, config_json:@config_json)
  end

  in_app_purchase_json = process_purchase_items(in_app_purchase_json:temp_iap_json, iap_tester:@iaptester)


  app_list_response = @app_store_connect.list_apps(filter: {
        bundle_id: @bundle_id
    })


  # puts app_list_response
  current_app = nil

  app_list_response[:data].each do |app_info|
    if app_info[:attributes][:bundle_id].to_s.eql?(@bundle_id)
        current_app = app_info
    end
  end

  app_id =  current_app[:id]

  puts " "
  puts "app_id :  #{app_id}  +++++++++"

  puts " "
  puts "创建消耗型购买项============="
  create_consumable_iap_items(appstore_client:@app_store_connect, app_id:app_id, in_app_purchase_items:in_app_purchase_json["consumable"])

  puts " "
  puts "创建非消耗型购买项============="
  create_consumable_iap_items(appstore_client:@app_store_connect, app_id:app_id, in_app_purchase_items:in_app_purchase_json["non_consumable"])

  puts " "
  puts "创建非续期订阅购买项============="
  create_consumable_iap_items(appstore_client:@app_store_connect, app_id:app_id, in_app_purchase_items:in_app_purchase_json["non_renew"])

  puts " "
  puts "创建自动订阅购买项============="
  create_subscriptions_groups(appstore_client:@app_store_connect, app_id:app_id, subscription_group_items:in_app_purchase_json["auto_renew"])

  update_app_share_secrets(app_id:app_id)
end

#create_iap_testerObject



771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
# File 'lib/pindo/command/deploy/iap.rb', line 771

def create_iap_tester()

      sandbox_tester_file = File.join(@iapconfig_dir, "iap_tester.json")
      sandbox_tester_json = {}
      if File.exist?(sandbox_tester_file)
        sandbox_tester_json = JSON.parse(File.read(sandbox_tester_file))
      else
        raise Informative, "缺少沙盒配置文件iap_tester.json !!!"
      end

      @iaptester = nil
      if !sandbox_tester_json.nil? && !sandbox_tester_json["iaptester"].nil?
        @iaptester = sandbox_tester_json["iaptester"]
      end

      if !@iaptester.nil? && @iaptester["need_create"]
          puts
          puts
          if itc_has_sandbox_tester(email:@iaptester["email"])

              puts "已存在沙盒账号:#{@iaptester["email"]},无需创建!!!"
          else
              puts "没有沙盒账号:#{@iaptester["email"]},需新创建!!!"

              create_iap_tester_ex()
              if itc_has_sandbox_tester(email:@iaptester["email"])
                puts "沙盒账号:#{@iaptester["email"]},创建成功!!!"
              else
                raise Informative, "沙盒账号:#{@iaptester["email"]},创建失败!!!"
              end
          end
      else
        raise Informative, "没有Sandbox Tester !!!"
      end

end

#create_iap_tester_exObject



732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
# File 'lib/pindo/command/deploy/iap.rb', line 732

def create_iap_tester_ex( )
  b_create_success = false
  testers = nil
    time = Time.local(1995 - rand(10), 12 - rand(10), 25- rand(20))
    birth_date = time.strftime("%Y-%m-%d")
    begin
      testers = Spaceship::ConnectAPI::SandboxTester.create(
        first_name: @iaptester['first_name'],
        last_name: @iaptester['last_name'],
        email: @iaptester['email'],
        password: @iaptester['password'],
        confirm_password: @iaptester['password'],
        secret_question:  @iaptester['password'] + '1234?',
        secret_answer: @iaptester['password'],
        birth_date:birth_date,
        app_store_territory: @iaptester['territory'] || 'USA'
      )
  rescue => err
      b_create_success = false
  end

  # if !b_create_success || testers.nil?
  #     begin
  #       testers = Spaceship::Tunes::SandboxTester.create!(
  #           email: @iaptester['email'],
  #           password: @iaptester['password'],
  #           first_name: @iaptester['first_name'],
  #           last_name: @iaptester['last_name'],
  #           country: @iaptester['territory'] || 'USA'
  #         )
  #       puts testers
  #     rescue => err

  #     end
  # end

end

#download_appstore_iap(appstore_iap_file: nil) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/pindo/command/deploy/iap.rb', line 95

def download_appstore_iap(appstore_iap_file:nil)
    puts "正在下载appstore iap 信息 ..."

    app_list_response = @app_store_connect.list_apps(filter: {
          bundle_id: @bundle_id
      })

    current_app = nil
    app_list_response[:data].each do |app_info|
      if app_info[:attributes][:bundle_id].to_s.eql?(@bundle_id)
          current_app = app_info
      end
    end

    app_id =  current_app[:id]

    puts " "
    puts "app_id :  #{app_id}  +++++++++"

    in_app_purchase_json = {}

    puts "正在下载消耗型购买项..."
    in_app_purchase_type = "CONSUMABLE"
    in_app_purchase_json["consumable"] = get_consumable_iap_items(appstore_client:@app_store_connect, app_id:app_id, in_app_purchase_type:in_app_purchase_type) || []

    puts "正在下载非消耗型购买项..."
    in_app_purchase_type = "NON_CONSUMABLE"
    in_app_purchase_json["non_consumable"] = get_consumable_iap_items(appstore_client:@app_store_connect, app_id:app_id, in_app_purchase_type:in_app_purchase_type) || []

    puts "正在下载非自动订阅购买项..."
    in_app_purchase_type = "NON_RENEWING_SUBSCRIPTION"
    in_app_purchase_json["non_renew"] = get_consumable_iap_items(appstore_client:@app_store_connect, app_id:app_id, in_app_purchase_type:in_app_purchase_type) || []

    puts "正在下载自动订阅购买项..."
    subscription_group_items = get_subscriptions_groups(appstore_client:@app_store_connect, app_id:app_id)
    in_app_purchase_json["auto_renew"] = subscription_group_items

    puts JSON.pretty_generate(in_app_purchase_json)
    File.open(appstore_iap_file, "w") do |f|
      f.write(JSON.pretty_generate(in_app_purchase_json))
    end

    pindo_dir = File::expand_path(pindo_single_config.pindo_dir)
    config_repo_dir = File.join(pindo_dir, @deploy_identifier)
    git_addpush_repo(path:config_repo_dir, message:"download app iap", commit_file_params:["fastlane/iap/iap_appstore_download.json"])

    update_app_share_secrets(app_id:app_id, need_create:false)
end

#get_gate_vip_items(app_type: nil, boss_config: nil) ⇒ Object



464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# File 'lib/pindo/command/deploy/iap.rb', line 464

def get_gate_vip_items(app_type:nil, boss_config:nil)
    vip_items = nil

    offer_ids = []
    if !boss_config.nil? && !boss_config["content"].nil? && !boss_config["content"]["client"].nil? && !boss_config["content"]["client"]["vip"].nil? && !boss_config["content"]["client"]["vip"]["style_list"].nil?
        style_list = boss_config["content"]["client"]["vip"]["style_list"] || {}
        style_item = style_list.find { |item| item["style"].eql?("tribble_style")}
        offer_ids = style_item["offer"] || []
    end

    if !boss_config.nil? && !boss_config["content"].nil? && !boss_config["content"]["common"].nil? && !boss_config["content"]["common"].nil?  && !boss_config["content"]["common"]["offer_map"].nil?
         boss_vip_items = boss_config["content"]["common"]["offer_map"]
         vip_items = vip_items || {}
         offer_ids.each do |offer_id|
            if !boss_vip_items[offer_id].nil?
              vip_items[offer_id] = boss_vip_items[offer_id]
            end
         end
    end

    return vip_items
end

#itc_has_sandbox_tester(email: nil) ⇒ Object



691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
# File 'lib/pindo/command/deploy/iap.rb', line 691

def itc_has_sandbox_tester(email:nil)

     = false
    begin
          response = @app_store_connect.list_sandbox_testers()
          # puts JSON.pretty_generate(response)
           = false
          response[:data].each do |tester_item|
            if tester_item[:attributes][:ac_account_name].to_s.eql?(@iaptester['email'])
               = true
              # puts "itc_has_sandbox_tester SandboxTester :  " + @iaptester['email'] + "账号已经存在"
            end
          end
    rescue => err

    end

    if !

      begin
          testers = Spaceship::ConnectAPI::SandboxTester.all()
          if !testers.nil? && testers.size > 0
              testers.each do | tester_item |
                  # puts tester_item.email
                if tester_item.email.to_s.eql?(@iaptester['email'])
                   = true
                  # puts "itc_has_sandbox_tester ConnectAPI SandboxTester :  " + @iaptester['email'] + "账号已经存在"
                end
              end
          end
      rescue => err

      end

    end

    return 
end

#login_api_key(apple_id: nil) ⇒ Object



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/pindo/command/deploy/iap.rb', line 338

def  (apple_id:nil)

  load_apikey_config = false
  api_key_json = nil
  pindo_dir = File::expand_path(pindo_single_config.pindo_dir)
  api_key_file = File.join(pindo_dir, "api_key.json")

  if File.exist?(api_key_file)
    api_key_json = JSON.parse(File.read(api_key_file))
    if !api_key_json.nil? && !api_key_json[apple_id].nil? && !api_key_json[apple_id]["issuer_id"].nil?
      issuer_id = api_key_json[apple_id]["issuer_id"]
      key_id = api_key_json[apple_id]["key_id"]
      private_key = api_key_json[apple_id]["private_key"]
      load_apikey_config = true
    end
  end

  if !load_apikey_config
    issuer_id = ask('请输入 issuer_id: ')
    key_id = ask('请输入 key_id: ')
    private_key_file = ask('请输入private key的文件路径: ')
    private_key = File.read(File.new(private_key_file))

    api_key_json = api_key_json || {}
    api_key_json[apple_id] = api_key_json[apple_id] || {}
    api_key_json[apple_id]["issuer_id"] = issuer_id
    api_key_json[apple_id]["key_id"] = key_id
    api_key_json[apple_id]["private_key"] = private_key

    answer = agree("请确认上面信息是否正确(Y/n):")
    unless answer
      raise Informative, "重新输入 !!!"
    end

    File.open(api_key_file, "w") do |f|
      f.write(JSON.pretty_generate(api_key_json))
    end
    load_apikey_config = true


  end

  if load_apikey_config

    puts "issuer_id : #{issuer_id}"
    puts "key_id  : #{key_id}"
    puts "private_key  : #{private_key}"

    AppStoreDevApi.config = {
      issuer_id: issuer_id,
      key_id: key_id,
      private_key: private_key
    }
    @app_store_connect = AppStoreDevApi::Client.new
  end
end

#process_consumable_iap_items(in_app_purchase_type: nil, in_app_purchase_items: nil, iap_tester: nil) ⇒ Object



522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# File 'lib/pindo/command/deploy/iap.rb', line 522

def process_consumable_iap_items(in_app_purchase_type:nil, in_app_purchase_items:nil, iap_tester:nil)

    tier_json = get_price_tier_dict
    iap_consumable_tier_dict = tier_json["consumable_price_tier"]

    in_app_purchase_items = in_app_purchase_items || []
    new_in_app_purchase_items = []
    in_app_purchase_items.each do |purchase_item|
        new_iap_items = {}
        new_iap_items["reference_name"] = purchase_item["reference_name"].to_s.strip || purchase_item["product_name"].to_s.strip
        if !purchase_item["reference_name"].nil? && purchase_item["reference_name"].length > 64
            puts purchase_item["reference_name"]
            puts "length: #{purchase_item["reference_name"].size}"
            raise Informative, "Reference Name 超出限定的64个字符 !!!"
        end

        temp_product_id = purchase_item["product_id"].to_s.strip
        new_iap_items["product_id"] = temp_product_id
        if new_iap_items["product_id"].include?("PRODUCT_BUNDLE_IDENTIFIER")
          temp_product_id = new_iap_items["product_id"]
          temp_product_id = temp_product_id.gsub(/PRODUCT_BUNDLE_IDENTIFIER/, @bundle_id);
          new_iap_items["product_id"] = temp_product_id
        end
        if !new_iap_items["product_id"].nil? && new_iap_items["product_id"].length > 100
            puts temp_product_id
            raise Informative, "product_id 超出限定的100个字符 !!!"
        end

        new_iap_items["in_app_purchase_type"] = in_app_purchase_type
        new_iap_items["price"] = purchase_item["price"].to_s.strip
        new_iap_items["price_tier"] = iap_consumable_tier_dict[new_iap_items["price"].to_s]

        if new_iap_items["price_tier"].nil?
          raise "购买项价格错误 " + new_iap_items["product_id"] + " 价格 :" + purchase_item["price"]
        end

        new_iap_items["localization"] = {}
        new_iap_items["localization"]["en-US"] = {}
        new_iap_items["localization"]["en-US"]["locale"] = "en-US"
        new_iap_items["localization"]["en-US"]["display_name"] = purchase_item["display_name"].to_s.strip

        if !new_iap_items["localization"]["en-US"]["display_name"].nil? && new_iap_items["localization"]["en-US"]["display_name"].length > 30
            puts temp_product_id
            raise Informative, "Display Name 超出限定的30个字符 !!!"
        end

        new_iap_items["localization"]["en-US"]["description"] = purchase_item["description"].to_s.strip
        if !new_iap_items["localization"]["en-US"]["description"].nil? && new_iap_items["localization"]["en-US"]["description"].length > 45
            puts temp_product_id
            raise Informative, "purchuse description 超出限定的45个字符 !!!"
        end

        new_iap_items["review_note"] = "username: " + iap_tester["email"] + "      password: " + iap_tester["password"]
        if !purchase_item["review_screenshot"].nil?
            new_iap_items["review_screenshot"] = File.basename(purchase_item["review_screenshot"])
            new_iap_items["review_screenshot_fullpath"] = File.join(@iapconfig_dir,  new_iap_items["review_screenshot"])
        else
            new_iap_items["review_screenshot_fullpath"] = nil
        end

        new_in_app_purchase_items << new_iap_items
    end

    return new_in_app_purchase_items
end

#process_purchase_items(in_app_purchase_json: nil, iap_tester: nil) ⇒ Object



487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'lib/pindo/command/deploy/iap.rb', line 487

def process_purchase_items(in_app_purchase_json:nil, iap_tester:nil)
    new_in_app_purchase_json = {}
    new_in_app_purchase_json["iaptester"] = @iaptester
    new_in_app_purchase_json["bundle_id"] = @bundle_id

    new_in_app_purchase_json["review_note"] = "username: " + iap_tester["email"] + "      password: " + iap_tester["password"]

    puts
    puts
    puts new_in_app_purchase_json["review_note"]

    in_app_purchase_type = "CONSUMABLE"
    items = process_consumable_iap_items(in_app_purchase_type:in_app_purchase_type, in_app_purchase_items:in_app_purchase_json["consumable"], iap_tester:iap_tester)
    new_in_app_purchase_json["consumable"] = items

    in_app_purchase_type = "NON_CONSUMABLE"
    items = process_consumable_iap_items(in_app_purchase_type:in_app_purchase_type, in_app_purchase_items:in_app_purchase_json["non_consumable"], iap_tester:iap_tester)
    new_in_app_purchase_json["non_consumable"] = items

    in_app_purchase_type = "NON_RENEWING_SUBSCRIPTION"
    items = process_consumable_iap_items(in_app_purchase_type:in_app_purchase_type, in_app_purchase_items:in_app_purchase_json["non_renew"], iap_tester:iap_tester)
    new_in_app_purchase_json["non_renew"] = items

    in_app_purchase_type = "Subscriptions"
    new_subscrptions_json = process_subscriptions_json(subscription_json:in_app_purchase_json["auto_renew"], iap_tester:iap_tester)
    new_in_app_purchase_json["auto_renew"] = new_subscrptions_json

    File.open(File.join(@iapconfig_dir, "iap_log.json"), "w") do |f|
      f.write(JSON.pretty_generate(new_in_app_purchase_json))
    end

    return new_in_app_purchase_json;

end

#process_subscriptions_item(subscription_items: nil, iap_tester: nil, subscription_duration_dict: nil) ⇒ Object



626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
# File 'lib/pindo/command/deploy/iap.rb', line 626

def process_subscriptions_item(subscription_items:nil, iap_tester:nil, subscription_duration_dict:nil)


  subscription_items = subscription_items || []
  new_subscription_items = []
    subscription_items.each do |subs_item|
      new_subs_item = {}

      new_subs_item["reference_name"] = subs_item["reference_name"].to_s.strip || subs_item["product_name"].to_s.strip
      if !new_subs_item["reference_name"].nil? && new_subs_item["reference_name"].length > 64
          puts new_subs_item["reference_name"]
          raise Informative, " Reference Name 超出限定的64个字符 !!!"
      end

      new_subs_item["product_id"] = subs_item["product_id"].to_s.strip
      temp_product_id = new_subs_item["product_id"]
      if new_subs_item["product_id"].include?("PRODUCT_BUNDLE_IDENTIFIER")
        temp_product_id = new_subs_item["product_id"]
        temp_product_id = temp_product_id.gsub(/PRODUCT_BUNDLE_IDENTIFIER/, @bundle_id);
        new_subs_item["product_id"] = temp_product_id
      end

      if !new_subs_item["product_id"].nil? && new_subs_item["product_id"].length > 100
          puts temp_product_id
          raise Informative, "product_id 超出限定的100个字符 !!!"
      end

      new_subs_item["family_sharable"] = false
      new_subs_item["price"] = subs_item["price"].to_s.strip
      new_subs_item["subscription_duration"] = subscription_duration_dict[subs_item["subscription_duration"]]

      if !subs_item["subscription_free_trial"].nil?
        new_subs_item["subscription_free_trial"] = subs_item["subscription_free_trial"]
      end
      new_subs_item["localization"] = {}
      new_subs_item["localization"]["en-US"] = {}
      new_subs_item["localization"]["en-US"]["locale"] = "en-US"
      new_subs_item["localization"]["en-US"]["display_name"] = subs_item["display_name"].to_s.strip
      if !new_subs_item["localization"]["en-US"]["display_name"].nil? && new_subs_item["localization"]["en-US"]["display_name"].length > 30
          puts temp_product_id
          raise Informative, "Display Name 超出限定的30个字符 !!!"

      end
      new_subs_item["localization"]["en-US"]["description"] = subs_item["description"].to_s.strip
      if !new_subs_item["localization"]["en-US"]["description"].nil? && new_subs_item["localization"]["en-US"]["description"].length > 45
          puts temp_product_id
          raise Informative, "Description 超出限定的45个字符 !!!"
      end

      new_subs_item["review_note"] =  "username: " + iap_tester["email"] + "      password: " + iap_tester["password"]
      if !subs_item["review_screenshot"].nil?
          new_subs_item["review_screenshot"] = File.basename(subs_item["review_screenshot"])
          new_subs_item["review_screenshot_fullpath"] = File.join(@iapconfig_dir, new_subs_item["review_screenshot"])
      else
          new_subs_item["review_screenshot_fullpath"] = nil
      end


      new_subscription_items << new_subs_item
    end

  return new_subscription_items
end

#process_subscriptions_json(subscription_json: nil, iap_tester: nil) ⇒ Object



589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
# File 'lib/pindo/command/deploy/iap.rb', line 589

def process_subscriptions_json(subscription_json:nil, iap_tester:nil)

  tier_json = get_price_tier_dict
  subscription_json = subscription_json || []
  new_subscription_json = []
    subscription_json.each do |subscription_group_item|
      new_subscription_group_item = {}
      new_subscription_group_item["group_reference_name"] = subscription_group_item["group_reference_name"].to_s.strip
      new_subscription_group_item["localization"] = {}
      new_subscription_group_item["localization"]["en-US"] = {}
      new_subscription_group_item["localization"]["en-US"]["locale"] = "en-US"
      new_subscription_group_item["localization"]["en-US"]["group_display_name"] = subscription_group_item["group_display_name"].to_s.strip

      if !new_subscription_group_item["localization"]["en-US"]["group_display_name"].nil? && new_subscription_group_item["localization"]["en-US"]["group_display_name"].length > 45
          puts new_subscription_group_item["localization"]["en-US"]["group_display_name"]
          raise Informative, "group_display_name 超出限定的75个字符 !!!"
      end
      new_subscription_group_item["localization"]["en-US"]["custom_app_name"] = subscription_group_item["custom_app_name"].to_s.strip
      if !new_subscription_group_item["localization"]["en-US"]["custom_app_name"].nil? && new_subscription_group_item["localization"]["en-US"]["custom_app_name"].length > 45
          puts new_subscription_group_item["localization"]["en-US"]["custom_app_name"]
          raise Informative, "custom_app_name 超出限定的30个字符 !!!"
      end

      new_subscription_group_item["subscription_items"] = []

      old_subscription_group_items = subscription_group_item["subscription_items"] || []
      if old_subscription_group_items.size <= 0 && !subscription_group_item["items"].nil?
        old_subscription_group_items = subscription_group_item["items"] || []
      end

      new_subscription_group_item["subscription_items"] = process_subscriptions_item(subscription_items:old_subscription_group_items, iap_tester:iap_tester, subscription_duration_dict:tier_json["subscription_duration"])
      new_subscription_json << new_subscription_group_item
    end

    return new_subscription_json
end

#produce_boss_iap(appstore_iap_file: nil, vip_mode: "autovip") ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/pindo/command/deploy/iap.rb', line 144

def produce_boss_iap(appstore_iap_file:nil, vip_mode:"autovip")

    if !File.exist?(appstore_iap_file)

        return
    end

    appstore_iap_file =File::expand_path(appstore_iap_file)
    appstore_iap_json = JSON.parse(File.read(appstore_iap_file))

    boss_iap_file =File.join(File::dirname(appstore_iap_file), "iap_boss.json")


    if !appstore_iap_json.nil? && !appstore_iap_json["auto_renew"].nil?

        appstore_iap_json["auto_renew"].each do |vip_group_item|
              if !vip_group_item.nil?

                  appstore_iap_items = vip_group_item["items"] || vip_group_item["subscription_items"]

                  boss_iap_json = {
                    "client_vip" => {
                      "situation_list" => [],
                      "style_list" => []
                    },
                    "offer_map" => {}
                  }

                  situation_list_item = {
                        "situation" => "launch",
                        "style" => "tribble_style"
                  }
                  style_list_item = {
                        "style" => "tribble_style",
                        "best_deal" => "offer.id." + vip_mode + "0",
                        "offer" => []
                  }

                  if !appstore_iap_items.nil? && appstore_iap_items.size > 0
                      appstore_iap_items.each do |appstore_iap_item|
                          boss_iap_item = {}
                          boss_iap_item["offer_id"] = "offer.id." + vip_mode
                          boss_iap_item["kind"] = "vip"
                          boss_iap_item["way"] = "iap"
                          boss_iap_item["type"] = "auto_renewable_subscription"
                          boss_iap_item["subscription"] = {}

                          if !appstore_iap_item["subscription_free_trial"].nil? && appstore_iap_item["subscription_free_trial"].eql?("3d")
                            boss_iap_item["free_days"] = 3
                          end
                          boss_iap_item["iap"] = {}
                          boss_iap_item["iap"]["price"] = appstore_iap_item["price"]

                          if appstore_iap_item["subscription_duration"].include?("w")
                            boss_iap_item["offer_id"] = boss_iap_item["offer_id"] + "0"
                            boss_iap_item["subscription"]["period_type"] = "week"
                            boss_iap_item["subscription"]["period"] = appstore_iap_item["subscription_duration"].gsub('w', '').to_i
                          elsif appstore_iap_item["subscription_duration"].include?("m")
                            boss_iap_item["offer_id"] = boss_iap_item["offer_id"] + "1"
                            boss_iap_item["subscription"]["period_type"] = "month"
                            boss_iap_item["subscription"]["period"] = appstore_iap_item["subscription_duration"].gsub('m', '').to_i
                            boss_iap_item["iap"]["discount"] = 15
                          elsif appstore_iap_item["subscription_duration"].include?("y")
                            boss_iap_item["offer_id"] = boss_iap_item["offer_id"] + "2"
                            boss_iap_item["subscription"]["period_type"] = "year"
                            boss_iap_item["subscription"]["period"] = appstore_iap_item["subscription_duration"].gsub('y', '').to_i
                            boss_iap_item["iap"]["discount"] = 50
                          end

                          if !boss_iap_item["iap"]["price"].to_s.include?("$")
                            boss_iap_item["iap"]["price"] = "$" + boss_iap_item["iap"]["price"].to_s
                          end

                          boss_iap_item["iap"]["product_id"] = appstore_iap_item["product_id"]
                          if boss_iap_item["iap"]["product_id"].include?("PRODUCT_BUNDLE_IDENTIFIER")
                            temp_product_id = boss_iap_item["iap"]["product_id"]
                            temp_product_id = temp_product_id.gsub(/PRODUCT_BUNDLE_IDENTIFIER/, @bundle_id);
                            boss_iap_item["iap"]["product_id"] = temp_product_id
                          end

                          boss_iap_json["offer_map"][boss_iap_item["offer_id"]] = boss_iap_item
                          style_list_item["offer"] << boss_iap_item["offer_id"]
                      end

                      if style_list_item["offer"].size == 3
                        situation_list_item["style"] = "tribble_style"
                        style_list_item["style"] = "tribble_style"
                      elsif style_list_item["offer"].size == 2
                        situation_list_item["style"] = "double_style"
                        style_list_item["style"] = "double_style"
                      elsif style_list_item["offer"].size == 1
                        situation_list_item["style"] = "single_style"
                        style_list_item["style"] = "single_style"
                      end

                      boss_iap_json["client_vip"]["situation_list"] << situation_list_item
                      boss_iap_json["client_vip"]["style_list"] << style_list_item
                  end

                  puts JSON.pretty_generate(boss_iap_json)
                  puts "\n\n\n"
                  File.open(boss_iap_file, "w") do |f|
                    f.write(JSON.pretty_generate(boss_iap_json))
                  end


              end
          end
      end

end

#runObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/pindo/command/deploy/iap.rb', line 56

def run


    if @download_flag

        (apple_id:@apple_id)
        Spaceship::Tunes.(@apple_id)

        appstore_iap_file = File.join(@iapconfig_dir, "iap_appstore_download.json")
        download_appstore_iap(appstore_iap_file:appstore_iap_file)
    elsif @boss_flag

        # puts "default boss vip auto =========\n\n\n"
        # appstore_iap_file = File.join(@iapconfig_dir, "iap_appstore.json")
        # produce_boss_iap(appstore_iap_file:appstore_iap_file, vip_mode:"autovip")

        puts "one === first auto vip  for boss  =========\n\n\n"
        appstore_iap_file = File.join(@iapconfig_dir, "one/iap_appstore.json")
        produce_boss_iap(appstore_iap_file:appstore_iap_file, vip_mode:"autovip")

        puts "two === second fancy vip  for boss  =========\n\n\n"
        appstore_iap_file = File.join(@iapconfig_dir, "two/iap_appstore.json")
        produce_boss_iap(appstore_iap_file:appstore_iap_file, vip_mode:"fancyvip")

        puts "three === third funny vip  for boss  =========\n\n\n"
        appstore_iap_file = File.join(@iapconfig_dir, "three/iap_appstore.json")
        produce_boss_iap(appstore_iap_file:appstore_iap_file, vip_mode:"funnyvip")

    else

        (apple_id:@apple_id)
        Spaceship::Tunes.(@apple_id)

        create_iap_tester()
        appstore_iap_file = File.join(@iapconfig_dir, "iap_appstore.json")
        create_appstore_iap(appstore_iap_file:appstore_iap_file)
    end
end

#update_app_share_secrets(app_id: nil, need_create: true) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/pindo/command/deploy/iap.rb', line 257

def update_app_share_secrets(app_id:nil, need_create:true)

    app_secret_id = get_app_share_secrets(app_id:app_id, need_create:need_create)
    if !app_secret_id.nil?
        puts
        puts "App Shared Secret:  #{app_secret_id}"
        puts
        pindo_dir = File::expand_path(pindo_single_config.pindo_dir)
        config_repo_dir = File.join(pindo_dir, @deploy_identifier)

        app_origin_config = File.join(config_repo_dir, "config.json")
        config_json = JSON.parse(File.read(app_origin_config))
        config_json['app_info']['appstore_iap_secret'] = app_secret_id
        File.open(app_origin_config, "w") do |file|
            file.write(JSON.pretty_generate(config_json))
            file.close
        end

        config_json = JSON.parse(File.read(@args_appconfig_fullname))
        config_json['app_info']['appstore_iap_secret'] = app_secret_id
        File.open(@args_appconfig_fullname, "w") do |file|
            file.write(JSON.pretty_generate(config_json))
            file.close
        end

        git_addpush_repo(path:config_repo_dir, message:"update app shared secret", commit_file_params:["config.json"])

    end


end

#validate!Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pindo/command/deploy/iap.rb', line 35

def validate!
  super

  pindo_dir = File::expand_path(pindo_single_config.pindo_dir)
  config_repo_dir = File.join(pindo_dir, @bundle_id)
  @iapconfig_dir =File.join(config_repo_dir, "fastlane/iap")

  puts "iap dir: " + @iapconfig_dir
  puts

end