• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Receipt类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.amazon.device.iap.model.Receipt的典型用法代码示例。如果您正苦于以下问题:Java Receipt类的具体用法?Java Receipt怎么用?Java Receipt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Receipt类属于com.amazon.device.iap.model包,在下文中一共展示了Receipt类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: onPurchaseUpdatesResponse

import com.amazon.device.iap.model.Receipt; //导入依赖的package包/类
@SuppressWarnings({"ConstantConditions", "ToArrayCallWithZeroLengthArrayArgument"})
@Override
public void onPurchaseUpdatesResponse(PurchaseUpdatesResponse response) {
    logDebug("onPurchaseUpdatesResponse " + response.getRequestStatus());
    if (response == null)
        return;
    if (response.getRequestStatus() == PurchaseUpdatesResponse.RequestStatus.SUCCESSFUL) {
        Receipt[] receipts = response.getReceipts().toArray(new Receipt[0]);
        for (Receipt receipt : receipts) {
            if (receipt != null && !receipt.isCanceled()) {
                if (receipt.getProductType() == ProductType.ENTITLED) {
                    amazonBillingService.productOwned(receipt.getSku(), true);
                    logDebug("onPurchaseUpdatesResponse productOwned: " + receipt.getSku());
                } else if (receipt.getProductType() == ProductType.SUBSCRIPTION) {
                    amazonBillingService.subscriptionOwned(receipt.getSku(), true);
                    logDebug("onPurchaseUpdatesResponse subscriptionOwned: " + receipt.getSku());
                }
            }
        }
    }
}
 
开发者ID:eggheadgames,项目名称:android-in-app-payments,代码行数:22,代码来源:AmazonBillingListener.java


示例2: onPurchaseUpdatesResponse

import com.amazon.device.iap.model.Receipt; //导入依赖的package包/类
@Override
public void onPurchaseUpdatesResponse(PurchaseUpdatesResponse response) {

    if (response.getRequestId().equals(mAlreadyPurchasedRequestId)) {
        for (Receipt receipt: response.getReceipts()) {
            if (receipt.getSku().equals(mAlreadyPurchasedProductId)) {

                final PurchaseCallback callback = mPurchaseCallbacks.get(response.getRequestId());
                if (callback != null) {
                    mPurchaseCallbacks.remove(response.getRequestId());
                }

                validatePurchase(receipt, response.getUserData().getUserId(), callback);
            }
        }
        mAlreadyPurchasedProductId = null;
        mAlreadyPurchasedRequestId = null;
    }
}
 
开发者ID:ludei,项目名称:atomic-plugins-inapps,代码行数:20,代码来源:AmazonInAppService.java


示例3: AmazonPurchase

import com.amazon.device.iap.model.Receipt; //导入依赖的package包/类
public AmazonPurchase(@NonNull final String originalJson) throws JSONException {
    super(originalJson);
    final ProductType productType = ProductType.valueOf(jsonObject.getString(NAME_ITEM_TYPE));
    if (productType == null) {
        throw new JSONException("Unknown product type.");
    }
    final ReceiptBuilder builder = new ReceiptBuilder()
            .setSku(sku)
            .setReceiptId(jsonObject.getString(NAME_RECEIPT_ID))
            .setPurchaseDate(AmazonUtils.readDate(jsonObject, NAME_PURCHASE_DATE));
    builder.setProductType(productType);
    if (jsonObject.has(NAME_CANCEL_DATE)) {
        builder.setCancelDate(AmazonUtils.readDate(jsonObject, NAME_CANCEL_DATE));
    }
    this.receipt = new Receipt(builder);
}
 
开发者ID:onepf,项目名称:OPFIab,代码行数:17,代码来源:AmazonPurchase.java


示例4: generateOriginalJson

import com.amazon.device.iap.model.Receipt; //导入依赖的package包/类
/**
 * Converts purchase response to json for transfer with purchase object
 * <p/>
 * <pre>
 * {
 * "orderId"           : "purchaseResponse.getRequestId"
 * "productId"         : "receipt.getSku"
 * "purchaseStatus"    : "purchaseRequestStatus.name"
 * "userId"            : "purchaseResponse.getUserId()" // if non-null
 * "itemType"          : "receipt.getItemType().name()" // if non-null
 * "purchaseToken"     : "receipt.getReceiptId()"
 * } </pre>
 *
 * @param purchaseResponse Purchase to convert.
 * @return Generate JSON from purchase.
 */
private String generateOriginalJson(@NotNull PurchaseResponse purchaseResponse) {
    final JSONObject json = new JSONObject();
    try {
        Receipt receipt = purchaseResponse.getReceipt();
        json.put(JSON_KEY_ORDER_ID, purchaseResponse.getRequestId());
        json.put(JSON_KEY_PRODUCT_ID, receipt.getSku());
        final PurchaseResponse.RequestStatus requestStatus = purchaseResponse.getRequestStatus();
        if (requestStatus != null) {
            json.put(JSON_KEY_PURCHASE_STATUS, requestStatus.name());
        }
        final UserData userData = purchaseResponse.getUserData();
        if (userData != null) {
            json.put(JSON_KEY_USER_ID, userData.getUserId());
        }
        final ProductType productType = receipt.getProductType();
        if (productType != null) {
            json.put(JSON_KEY_RECEIPT_ITEM_TYPE, productType.name());
        }
        json.put(JSON_KEY_RECEIPT_PURCHASE_TOKEN, receipt.getReceiptId());
        Logger.d("generateOriginalJson(): JSON\n", json);
    } catch (JSONException e) {
        Logger.e("generateOriginalJson() failed to generate JSON", e);
    }
    return json.toString();
}
 
开发者ID:onepf,项目名称:OpenIAB,代码行数:42,代码来源:AmazonAppstoreBillingService.java


示例5: validatePurchase

import com.amazon.device.iap.model.Receipt; //导入依赖的package包/类
protected void validatePurchase(Receipt receipt,String userId, final PurchaseCallback callback) {

        //local validation or server validation
        String unverifiedData =  "{\"userId\": \"" + userId + "\", \"purchaseToken\": \""
                + receipt.getReceiptId().replace("\n", "") + "\"}";


        final InAppPurchase purchase = new InAppPurchase();
        purchase.productId = receipt.getSku();
        purchase.transactionId = receipt.getReceiptId();
        purchase.quantity = 1;
        purchase.purchaseDate = new Date();

        super.validate(unverifiedData, purchase.productId, new ValidationCompletion() {
            @Override
            public void finishValidation(final Error error) {
                dispatchCallback(new Runnable() {
                    @Override
                    public void run() {
                        if (error != null) {
                            //validation failed
                            notifyPurchaseFailed(purchase.productId, error);
                        } else {
                            //validation completed, update stock and save it.
                            mStock.put(purchase.productId, 1);
                            saveCipheredStock();
                            notifyPurchaseCompleted(purchase);
                        }
                        if (callback != null) {
                            callback.onComplete(purchase, error);
                        }
                    }
                });
            }
        });

    }
 
开发者ID:ludei,项目名称:atomic-plugins-inapps,代码行数:38,代码来源:AmazonInAppService.java


示例6: convertReceiptToTransaction

import com.amazon.device.iap.model.Receipt; //导入依赖的package包/类
/** Converts a Receipt to our transaction object. */
static Transaction convertReceiptToTransaction(int i, String requestId, Receipt receipt, final UserData userData) {

	// build the transaction from the purchase object
	Transaction transaction = new Transaction();
	transaction.setIdentifier(receipt.getSku());
	transaction.setOrderId(receipt.getReceiptId());
	transaction.setStoreName(PurchaseManagerConfig.STORE_NAME_ANDROID_AMAZON);
	transaction.setRequestId(requestId);
	transaction.setUserId(userData.getUserId());
	transaction.setPurchaseTime(receipt.getPurchaseDate());
	transaction.setPurchaseText("Purchased: " + receipt.getSku().toString());
	// transaction.setPurchaseCost(receipt.getSku()); // TODO: GdxPay: impl.
	// parsing of COST + CURRENCY via skuDetails.getPrice()!
	// transaction.setPurchaseCostCurrency(null);

	if (receipt.isCanceled()) {
		// order has been refunded or cancelled
		transaction.setReversalTime(receipt.getCancelDate());
		// transaction.setReversalText(receipt..getPurchaseState() == 1 ?
		// "Cancelled" : "Refunded");
	} else {
		// still valid!
		transaction.setReversalTime(null);
		transaction.setReversalText(null);
	}

	transaction.setTransactionData(receipt.toJSON().toString());
	// transaction.setTransactionDataSignature(purchase.getSignature());

	return transaction;
}
 
开发者ID:libgdx,项目名称:gdx-pay,代码行数:33,代码来源:AmazonTransactionUtils.java


示例7: handleReceipt

import com.amazon.device.iap.model.Receipt; //导入依赖的package包/类
/**
  * Method to handle receipts
  * 
  * @param requestId
  * @param receipt
  * @param userData
  */
 public void handleReceipt(final String requestId, final Receipt receipt, final UserData userData) {

 	showMessage(LOGTYPELOG,  "Handle receipt: requestId (" + requestId
     + ") receipt: "
     + receipt
     + ")");
     
   // convert receipt to transaction
     Transaction trans = AmazonTransactionUtils.convertReceiptToTransaction(1, requestId, receipt, userData);	// provides cancleState also
			
 	switch (receipt.getProductType()) {
             
     case CONSUMABLE:
// inform the listener
observer.handlePurchase(trans);
         // Automatically consume item
     	PurchasingService.notifyFulfillment(receipt.getReceiptId(), FulfillmentResult.FULFILLED);
         break;
         
     case ENTITLED:
// inform the listener
observer.handlePurchase(trans);
         break;
         
     case SUBSCRIPTION:
         // TODO: check subscription sample for how to handle consumable purchases
         break;
     }
 }
 
开发者ID:libgdx,项目名称:gdx-pay,代码行数:37,代码来源:PurchaseManagerAndroidAmazon.java


示例8: convertPurchase

import com.amazon.device.iap.model.Receipt; //导入依赖的package包/类
/**
 * Transforms Amazon receipt into library purchase model.
 *
 * @param receipt Amazon receipt to transform.
 *
 * @return Newly constructed purchase object.
 */
@Nullable
public static Purchase convertPurchase(@NonNull final Receipt receipt) {
    final Purchase.Builder builder = new Purchase.Builder(receipt.getSku());
    final ProductType productType = receipt.getProductType();
    switch (productType) {
        case CONSUMABLE:
            builder.setType(SkuType.CONSUMABLE);
            break;
        case ENTITLED:
            builder.setType(SkuType.ENTITLEMENT);
            break;
        case SUBSCRIPTION:
            builder.setType(SkuType.SUBSCRIPTION);
            break;
        default:
            OPFLog.e("Unknown Amazon product type: " + productType);
            return null;
    }
    builder.setToken(receipt.getReceiptId());
    builder.setCanceled(receipt.isCanceled());
    builder.setPurchaseTime(receipt.getPurchaseDate().getTime());
    builder.setProviderName(AmazonBillingProvider.NAME);
    builder.setOriginalJson(receipt.toJSON().toString());

    return builder.build();
}
 
开发者ID:onepf,项目名称:OPFIab,代码行数:34,代码来源:AmazonUtils.java


示例9: getInventory

import com.amazon.device.iap.model.Receipt; //导入依赖的package包/类
@NonNull
public static Collection<Purchase> getInventory(
        @NonNull final PurchaseUpdatesResponse response) {

    final List<Receipt> receipts = response.getReceipts();
    final Collection<Purchase> purchases = new ArrayList<>(receipts.size());
    for (final Receipt receipt : receipts) {
        final Purchase purchase = convertPurchase(receipt);
        if (purchase != null) {
            purchases.add(purchase);
        }
    }

    return purchases;
}
 
开发者ID:onepf,项目名称:OPFIab,代码行数:16,代码来源:AmazonUtils.java


示例10: onPurchaseUpdatesResponse

import com.amazon.device.iap.model.Receipt; //导入依赖的package包/类
@Override
public void onPurchaseUpdatesResponse(final PurchaseUpdatesResponse purchaseUpdatesResponse) {
    final PurchaseUpdatesResponse.RequestStatus requestStatus = purchaseUpdatesResponse.getRequestStatus();
    final RequestId requestId = purchaseUpdatesResponse.getRequestId();
    Logger.d("onPurchaseUpdatesResponse() reqStatus: ", requestStatus,
            "reqId: ", requestId);

    switch (requestStatus) {
        case SUCCESSFUL:
            for (final String sku : inventory.getAllOwnedSkus()) {
                inventory.erasePurchase(sku);
            }
            final UserData userData = purchaseUpdatesResponse.getUserData();
            final String userId = userData.getUserId();
            if (!userId.equals(currentUserId)) {
                Logger.w("onPurchaseUpdatesResponse() Current UserId: ", currentUserId,
                        ", purchase UserId: ", userId);
                break;
            }
            for (final Receipt receipt : purchaseUpdatesResponse.getReceipts()) {
                inventory.addPurchase(getPurchase(receipt));
            }
            if (purchaseUpdatesResponse.hasMore()) {
                PurchasingService.getPurchaseUpdates(false);
                Logger.d("Initiating Another Purchase Updates with offset: ");
                return;
            }
            break;
        case FAILED:
            break;
    }
    final CountDownLatch countDownLatch = inventoryLatchQueue.poll();
    if (countDownLatch != null) {
        countDownLatch.countDown();
    }
}
 
开发者ID:onepf,项目名称:OpenIAB,代码行数:37,代码来源:AmazonAppstoreBillingService.java


示例11: getPurchase

import com.amazon.device.iap.model.Receipt; //导入依赖的package包/类
@NotNull
private Purchase getPurchase(@Nullable final Receipt receipt) {
    final Purchase purchase = new Purchase(OpenIabHelper.NAME_AMAZON);
    if (receipt == null) {
        return purchase;
    }

    final String storeSku = receipt.getSku();
    purchase.setSku(SkuManager.getInstance().getSku(OpenIabHelper.NAME_AMAZON, storeSku));
    purchase.setToken(receipt.getReceiptId());

    switch (receipt.getProductType()) {
        case CONSUMABLE:
            // TODO Make sure this behavior is intended
        case ENTITLED:
            purchase.setItemType(IabHelper.ITEM_TYPE_INAPP);
            Logger.d("Add to inventory SKU: ", storeSku);
            break;
        case SUBSCRIPTION:
            // TODO Make sure cancelDate is always available
            purchase.setItemType(IabHelper.ITEM_TYPE_SUBS);
            purchase.setSku(SkuManager.getInstance().getSku(OpenIabHelper.NAME_AMAZON, storeSku));
            Logger.d("Add subscription to inventory SKU: ", storeSku);
            break;
    }
    return purchase;
}
 
开发者ID:onepf,项目名称:OpenIAB,代码行数:28,代码来源:AmazonAppstoreBillingService.java


示例12: onPurchaseResponse

import com.amazon.device.iap.model.Receipt; //导入依赖的package包/类
@Override
public void onPurchaseResponse(PurchaseResponse response) {
    logDebug("onPurchaseResponse " + response.getRequestStatus());
    final String requestId = response.getRequestId().toString();
    final String userId = response.getUserData().getUserId();
    final PurchaseResponse.RequestStatus status = response.getRequestStatus();
    final Receipt receipt;
    logDebug("onPurchaseResponse: requestId (" + requestId + ") userId (" + userId + ") purchaseRequestStatus (" + status + ")");
    switch (status) {
        case SUCCESSFUL:
            receipt = response.getReceipt();
            if (receipt != null) {
                logDebug("onPurchaseResponse: receipt json:" + receipt.toJSON());
                logDebug("onPurchaseResponse: getUserId:" + response.getUserData().getUserId());
                logDebug("onPurchaseResponse: getMarketplace:" + response.getUserData().getMarketplace());

                if (receipt.getProductType() == ProductType.SUBSCRIPTION) {
                    amazonBillingService.subscriptionOwned(receipt.getSku(), false);
                } else {
                    amazonBillingService.productOwned(receipt.getSku(), false);
                }

                PurchasingService.notifyFulfillment(receipt.getReceiptId(), FulfillmentResult.FULFILLED);
            }
            break;
        case ALREADY_PURCHASED:
            logDebug("onPurchaseResponse: already purchased, you should verify the entitlement purchase on your side and make sure the purchase was granted to customer");
            receipt = response.getReceipt();
            if (receipt != null && !receipt.isCanceled()) {
                if (receipt.getProductType() == ProductType.SUBSCRIPTION) {
                    amazonBillingService.subscriptionOwned(receipt.getSku(), true);
                } else {
                    amazonBillingService.productOwned(receipt.getSku(), true);
                }
            }
            break;
        case INVALID_SKU:
            logDebug("onPurchaseResponse: invalid SKU!  onProductDataResponse should have disabled buy button already.");
            break;
        case FAILED:
        case NOT_SUPPORTED:
            logDebug("onPurchaseResponse: failed so remove purchase request from local storage");
            break;
    }
}
 
开发者ID:eggheadgames,项目名称:android-in-app-payments,代码行数:46,代码来源:AmazonBillingListener.java


示例13: onPurchaseUpdatesResponse

import com.amazon.device.iap.model.Receipt; //导入依赖的package包/类
/**
     * This is the callback for {@link PurchasingService#getPurchaseUpdates}.
     * 
     * You will receive Entitlement receipts from this callback.
     * 
     */
    @Override
    public void onPurchaseUpdatesResponse(final PurchaseUpdatesResponse response) {
    	showMessage(LOGTYPELOG,  "onPurchaseUpdatesResponse: requestId (" + response.getRequestId()
                   + ") purchaseUpdatesResponseStatus ("
                   + response.getRequestStatus()
                   + ") userId ("
                   + response.getUserData().getUserId()
                   + ")");
        final PurchaseUpdatesResponse.RequestStatus status = response.getRequestStatus();
        switch (status) {
        case SUCCESSFUL:

            updateUserData(response.getUserData());
            
//            for (final Receipt receipt : response.getReceipts()) {
//                handleReceipt(response.getRequestId().toString(), receipt, response.getUserData());
//            }

            // send result to observer --------
			List<Transaction> transactions = new ArrayList<Transaction>(response.getReceipts().size());

			Array<Receipt> consumables = new Array<Receipt>(response.getReceipts().size());
			for (int i = 0; i < response.getReceipts().size(); i++) {
				Receipt receipt = response.getReceipts().get(i);
				
				// Memoize consumables for later check
				if (receipt.getProductType() == ProductType.CONSUMABLE)
					consumables.add(receipt);

				transactions.add(AmazonTransactionUtils.convertReceiptToTransaction(i, response.getRequestId().toString(), receipt, response.getUserData()));
			}
			// send inventory to observer
			observer.handleRestore(transactions.toArray(new Transaction[transactions.size()]));

            // Automatically consume consumables if this was not previously the case
			for (int i = 0; i < consumables.size; i++) {
				Receipt consumable = consumables.get(i);
	        	PurchasingService.notifyFulfillment(consumable.getReceiptId(), FulfillmentResult.FULFILLED);
			}
			
			//---- check if there are more receipts -------
            if (response.hasMore()) {
                PurchasingService.getPurchaseUpdates(false);
            }
            break;
            
        case FAILED:
        	showMessage(LOGTYPEERROR,  "onPurchaseUpdatesResponse: FAILED, should retry request");
        	observer.handleRestoreError(new Throwable("onPurchaseUpdatesResponse: FAILED, should retry request"));
      		break;
      		
        case NOT_SUPPORTED:
        	showMessage(LOGTYPEERROR,  "onPurchaseUpdatesResponse: NOT_SUPPORTED, should retry request");
        	observer.handleRestoreError(new Throwable("onPurchaseUpdatesResponse: NOT_SUPPORTED, should retry request"));
            break;
        }

    }
 
开发者ID:libgdx,项目名称:gdx-pay,代码行数:65,代码来源:PurchaseManagerAndroidAmazon.java


示例14: onPurchaseResponse

import com.amazon.device.iap.model.Receipt; //导入依赖的package包/类
/**
 * This is the callback for {@link PurchasingService#purchase}. For each
 * time the application sends a purchase request
 * {@link PurchasingService#purchase}, Amazon Appstore will call this
 * callback when the purchase request is completed. If the RequestStatus is
 * Successful or AlreadyPurchased then application needs to call
 * {@link SampleIAPManager#handleReceipt} to handle the purchase
 * fulfillment. If the RequestStatus is INVALID_SKU, NOT_SUPPORTED, or
 * FAILED, notify corresponding method of {@link SampleIAPManager} .
 */
@Override
public void onPurchaseResponse(final PurchaseResponse response) {
    final String requestId = response.getRequestId().toString();
    final String userId = response.getUserData().getUserId();
    final PurchaseResponse.RequestStatus status = response.getRequestStatus();
    showMessage(LOGTYPELOG,  "onPurchaseResponse: requestId (" + requestId
               + ") userId ("
               + userId
               + ") purchaseRequestStatus ("
               + status
               + ")");

    switch (status) {
    case SUCCESSFUL:
        final Receipt receipt = response.getReceipt();
        
        updateUserData(response.getUserData());
        showMessage(LOGTYPELOG,  "onPurchaseResponse: receipt json:" + receipt.toJSON());
        handleReceipt(response.getRequestId().toString(), receipt, response.getUserData());
        break;
        
    case ALREADY_PURCHASED:
    	showMessage(LOGTYPELOG, "onPurchaseResponse: already purchased, you should verify the entitlement purchase on your side and make sure the purchase was granted to customer");
    	observer.handlePurchaseError(new Throwable("onPurchaseResponse: ALREADY_PURCHASED"));
        break;
        
    case INVALID_SKU:
    	showMessage(LOGTYPEERROR, 
              "onPurchaseResponse: invalid SKU!  onProductDataResponse should have disabled buy button already.");
    	observer.handlePurchaseError(new Throwable("onPurchaseResponse: INVALID_SKU"));
        break;
        
    case FAILED:
    	showMessage(LOGTYPEERROR, "onPurchaseResponse: FAILED");
    	observer.handlePurchaseError(new Throwable("onPurchaseResponse: FAILED"));
        break;
        
    case NOT_SUPPORTED:
    	showMessage(LOGTYPEERROR,  "onPurchaseResponse: NOT_SUPPORTED so remove purchase request from local storage");
    	observer.handlePurchaseError(new Throwable("onPurchaseResponse: NOT_SUPPORTED"));
        break;
    }
}
 
开发者ID:libgdx,项目名称:gdx-pay,代码行数:54,代码来源:PurchaseManagerAndroidAmazon.java



注:本文中的com.amazon.device.iap.model.Receipt类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BarChart类代码示例发布时间:2022-05-23
下一篇:
Java SecureDirectoryStream类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap