예제 #1
0
  public NewGuideView(TouristMidlet midlet) {
    super(midlet);
    setTitle("Buy guide");
    setLayout(new BorderLayout());
    getStyle().setBgColor(Visual.BACKGROUND_COLOR);

    loadingForm = new Form("Buy guide");
    loadingForm.setLayout(new BorderLayout());
    loadingComp = new LoadingComponent(this);
    loadingForm.addComponent(BorderLayout.CENTER, loadingComp);

    /* See the flow of In-App Purchasing at:
     * http://www.developer.nokia.com/Resources/Library/Java/#!developers-guides/in-app-purchase.html */
    try {
      manager = IAPClientPaymentManager.getIAPClientPaymentManager();
      IAPClientPaymentManager.setIAPClientPaymentListener(this);
    } catch (Exception e) {
      Util.showAlert(e.getClass().getName(), "Could not initialize In-App Purchase manager");
    }

    newGuideList = new NewGuideList(this);
    addComponent(BorderLayout.CENTER, newGuideList);

    loginButton = new Button("Login to see past purchases");
    loginButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            loadAccountAndGuides();
          }
        });
    addCommands();

    revalidate();
  }
예제 #2
0
 /**
  * Purchases a guide.
  *
  * @param guide Guide to be purchased.
  */
 public void purchase(Guide guide) {
   int status =
       manager.purchaseProduct(
           guide.getId(), IAPClientPaymentManager.FORCED_AUTOMATIC_RESTORATION);
   if (status != IAPClientPaymentManager.SUCCESS) {
     guide = null;
     Util.showAlert("Purchase failure", getPaymentError(status));
   }
 }
예제 #3
0
  private void loadAccountAndGuides() {
    if (loadingAccount) {
      return;
    }

    loadingAccount = true;
    showLoading(true);

    // For restoring guides user's account is needed
    int status = manager.getUserAndDeviceId(IAPClientPaymentManager.DEFAULT_AUTHENTICATION);

    if (status != IAPClientPaymentManager.SUCCESS) {
      Util.showAlert("Authorization failure", getPaymentError(status));
      newGuide = null;
      loadingAccount = false;
    }
  }
예제 #4
0
  private void loadProductData() {
    if (waitingProductData.isEmpty()) {
      waitingProductData = null;
      loadingGuides = false;
      return;
    }

    String[] productIds = new String[waitingProductData.size()];
    Enumeration e = waitingProductData.keys();

    for (int i = 0; e.hasMoreElements(); i++) {
      productIds[i] = ((String) e.nextElement());
    }

    int status = manager.getProductData(productIds);
    if (status != IAPClientPaymentManager.SUCCESS) {
      waitingProductData = null;
      Util.showAlert("Metadata failure", getPaymentError(status));
      midlet.showGuideView();
      loadingGuides = false;
    }
  }
예제 #5
0
 public final void productDataReceived(int status, IAPClientProductData productData) {
   newGuide.setCity(productData.getShortDescription());
   newGuide.setPrice(productData.getPrice());
   newGuide.setUrl(GUIDE_URL_PREFIX + newGuide.getId());
   manager.purchaseProduct(newGuide.getId(), IAPClientPaymentManager.FORCED_AUTOMATIC_RESTORATION);
 }