【问题标题】:Exemplary code for payment支付示例代码
【发布时间】:2017-03-18 03:20:49
【问题描述】:

有人可以为我提供一个有效的支付类吗?我的代码如下。

我的问题是:我的购买方法在付款成功之前返回true。 (换句话说:pay 方法返回一个令牌,然后要求登录 iTunes 或 google-play 商店。用户不得继续购买,因为他/她已经有可能继续购买。

public boolean purchase() {

  final Purchase p = Purchase.getInAppPurchase();
  boolean retVal = true;
  if (p != null) {
     if (p.isManagedPaymentSupported()) {
        if (Display.getInstance().getPlatformName().equalsIgnoreCase(Constants.ANDROID)) {
           p.purchase(Payment.SKUS_AND[this.membershipType]);
        }
        else {
           p.purchase(Payment.SKUS_IOS[this.membershipType]);
        }
     }
     else {
        String retToken = null;
        if (p.isManualPaymentSupported()) {
           if (Display.getInstance().getPlatformName().equalsIgnoreCase(Constants.IOS)) {
              retToken = p.pay(Payment.ITEM_COSTS[this.membershipType], Payment.CURRENCY, "lfiuhlecfhbweucfbhewucfbhewluh");
           }
           else {
              retToken = p.pay(Payment.ITEM_COSTS[this.membershipType], Payment.CURRENCY, "6578346756347865783");
           }
           retVal = retToken != null;
        }
        else {
           UITools.infoDialog(Settings.getInstance().getLocalizedText(TextConstants.UNSUPPORTED_PAYMENT));
           retVal = false;
        }
     }
  }
  else {
     UITools.infoDialog(Settings.getInstance().getLocalizedText(TextConstants.UNSUPPORTED_PAYMENT));
     retVal = false;
  }
  return retVal;
}

【问题讨论】:

    标签: android ios in-app-purchase payment codenameone


    【解决方案1】:

    购买是异步的,因此当您调用 purchase 之类的方法时,它会立即返回,而无需确认或拒绝付款过程是否成功。

    您的主类必须实现PurchaseCallback,当购买成功/失败时,您将在其中收到适当的回调。具体来说itemPurchased应该在支付完成时调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-20
      • 2016-06-11
      • 2017-08-18
      • 2012-01-29
      • 2014-02-26
      • 1970-01-01
      • 2018-01-31
      • 1970-01-01
      相关资源
      最近更新 更多