Ionic 3, IOS, в приложении покупки - PullRequest
0 голосов
/ 01 мая 2018

Я реализовал IAP в своем приложении в качестве подписки, т. Е. Я пытаюсь восстановить покупку в случае успеха, я говорю, что пользователь подписан, в противном случае я говорю, что нет. если он этого не сделает, я предложу ему подписаться на мое приложение.

После нескольких отклонений от Apple, нам вчера позвонили, и они утверждают, что мой механизм восстановления не работает должным образом, и мне нужно переписать эту часть моего кода.

(услуга прилагается)

Во-первых, я не могу понять, откуда они знают, как я использую приложение, потому что js увеличено.

Я использую Ionic 3 с подключаемым в приложении 1 ионным плагином.

Код прикреплен

import { Injectable } from '@angular/core';
import * as _ from "lodash";
import {DbProvider} from "../db/db";
import {AlertController, Platform, ToastController} from "ionic-angular";
import {AuthProvider} from "../auth/auth";
import {TranslationProvider} from "../translation/translation";
import {InAppPurchase} from "@ionic-native/in-app-purchase";
import {TRIAL_PERIOD} from "../../app/app.constants";

/*
  Generated class for the BillingProvider provider.
  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class BillingProvider {

  product_id;
  inTrial;
  cashPay;
  subscriber;
  get isPaying() {
    if(this.inTrial){
      return true;
    } else {
      return this.cashPay || this.subscriber;
    }
  }

  constructor(private db: DbProvider, private alertCtrl: AlertController, private auth: AuthProvider, private translate: TranslationProvider, private toastCtrl: ToastController,
              private iapp: InAppPurchase, private platform: Platform) {
    this.init()
  }

  private async init() {
    await this.platform.ready();
    const product_ids = await this.db.getProductId();
    if (this.platform.is('ios')) {
      this.product_id = product_ids['ios'];
    } else {
      this.product_id = product_ids['android'];
    }
    await this.loadSubscribe();
    const {joined} = this.auth.currentUser;
    const joinDate = new Date(parseInt(joined));
    const diff = new Date().getTime() - joinDate.getTime();
    this.inTrial = diff < TRIAL_PERIOD;
    const inTrial = this.inTrial;
    this.auth.updateUser({inTrial});
    const {paying} = this.auth.currentUserText;
    this.cashPay = !!paying;
  }

  private async loadSubscribe() {
    try {
      const rawProducts = await this.iapp.restorePurchases();
      const products = JSON.stringify(rawProducts);
      this.auth.updateUser({products});
      const subscriber = !!_.find(rawProducts, {productId : this.product_id});
      this.auth.updateUser({subscriber});
      this.subscriber = subscriber;
    } catch (e) {
      console.log(e);
    }
  }

  private cashBuy(res, rej) {
    const alert = this.alertCtrl.create({
      title: this.translate.translate('Pay by cash request'),
      message: this.translate.translate('Please fill the details below'),
      inputs: [
        {
          name: 'name',
          placeholder: this.translate.translate('Full name')
        },
        {
          name: 'mail',
          placeholder: this.translate.translate('Email')
        },
        {
          name: 'phone',
          placeholder: this.translate.translate('Phone number')
        }
      ],
      buttons: [
        {
          text: this.translate.translate('Cancel'),
          handler: data => rej()
        },
        {
          text: this.translate.translate('Submit'),
          handler: data => {
            const user = this.auth.currentUserText;
            const row = _.pickBy({...data, ...user}, e => e);
            this.db.addCashRequest(row);
            const t = this.toastCtrl.create({
              message: this.translate.translate('We got your request, we will contact you soon.'),
              duration: 3000,
              position: 'bottom'
            });
            t.present();
            rej()
          }
        }
      ]
    });
    alert.present()
    //  asdasd
  }

  public buy() {
    return new Promise((res, rej) => {
      const alert = this.alertCtrl.create({
        title: this.translate.translate('Confirm purchase'),
        message: this.translate.translate('What Source you want to buy from'),
        buttons: [
          {
            text: this.translate.translate('From Store'),
            handler: () => {
              this.iapp.subscribe(this.product_id).then(res).catch(rej);
            }
          },
          {
            text: this.translate.translate('By Cash'),
            handler: () => {
              this.cashBuy(res, rej);
            }
          }
        ]
      });
      alert.present();
    })
  }

}
...