Search in sources :

Example 1 with PurchasingListener

use of com.amazon.device.iap.PurchasingListener in project zype-firebuilder by zype.

the class AmazonInAppPurchase method createIapPurchasingListener.

/**
 * Creates IAP purchase listener from PurchaseListener.
 */
/*package private*/
PurchasingListener createIapPurchasingListener(final PurchaseListener listener) {
    Log.d(TAG, "PurchasingListener registered");
    return new PurchasingListener() {

        @Override
        public void onUserDataResponse(UserDataResponse userDataResponse) {
            Log.d(TAG, "UserDataResponse received " + userDataResponse.toString());
            Response response = createResponse(isSuccessful(userDataResponse), userDataResponse.getRequestId().toString());
            UserData userData = createUserDataFromIapUserData(userDataResponse.getUserData());
            listener.onGetUserDataResponse(response, userData);
        }

        @Override
        public void onProductDataResponse(ProductDataResponse productDataResponse) {
            Log.d(TAG, "ProductDataResponse received " + productDataResponse.toString());
            Response response = createResponse(isSuccessful(productDataResponse), productDataResponse.getRequestId().toString());
            Map<String, Product> productMap = createProductMapFromProductDataResponse(productDataResponse.getProductData());
            listener.onProductDataResponse(response, productMap, productDataResponse.getUnavailableSkus());
        }

        @Override
        public void onPurchaseResponse(PurchaseResponse purchaseResponse) {
            Log.d(TAG, "purchaseResponse received " + purchaseResponse.toString());
            Response response = createResponse(isSuccessful(purchaseResponse), purchaseResponse.getRequestId().toString());
            com.amazon.device.iap.model.Receipt iapReceipt = purchaseResponse.getReceipt();
            String sku = null;
            if (iapReceipt != null) {
                sku = iapReceipt.getSku();
            }
            listener.onPurchaseResponse(response, sku, createReceipt(iapReceipt), createUserDataFromIapUserData(purchaseResponse.getUserData()));
        }

        @Override
        public void onPurchaseUpdatesResponse(PurchaseUpdatesResponse purchaseUpdatesResponse) {
            Log.d(TAG, "purchaseUpdatesResponse received " + purchaseUpdatesResponse.toString());
            Response response = createResponse(isSuccessful(purchaseUpdatesResponse), purchaseUpdatesResponse.getRequestId().toString());
            List<Receipt> receipts = createReceiptList(purchaseUpdatesResponse.getReceipts());
            UserData userData = createUserDataFromIapUserData(purchaseUpdatesResponse.getUserData());
            listener.onUserDataResponse(response, receipts, userData, purchaseUpdatesResponse.hasMore());
        }
    };
}
Also used : UserDataResponse(com.amazon.device.iap.model.UserDataResponse) PurchasingListener(com.amazon.device.iap.PurchasingListener) Receipt(com.amazon.purchase.model.Receipt) UserData(com.amazon.purchase.model.UserData) Product(com.amazon.purchase.model.Product) PurchaseResponse(com.amazon.device.iap.model.PurchaseResponse) ProductDataResponse(com.amazon.device.iap.model.ProductDataResponse) Response(com.amazon.purchase.model.Response) PurchaseUpdatesResponse(com.amazon.device.iap.model.PurchaseUpdatesResponse) PurchaseResponse(com.amazon.device.iap.model.PurchaseResponse) UserDataResponse(com.amazon.device.iap.model.UserDataResponse) ProductDataResponse(com.amazon.device.iap.model.ProductDataResponse) PurchaseUpdatesResponse(com.amazon.device.iap.model.PurchaseUpdatesResponse)

Example 2 with PurchasingListener

use of com.amazon.device.iap.PurchasingListener in project zype-firebuilder by zype.

the class AmazonInAppPurchase method registerDefaultPurchaseListener.

/**
 * {@inheritDoc}
 */
@Override
public void registerDefaultPurchaseListener(PurchaseListener purchaseListener) {
    this.mPurchaseListener = purchaseListener;
    PurchasingListener iapListener = createIapPurchasingListener(purchaseListener);
    PurchasingService.registerListener(mContext, iapListener);
    Log.d(TAG, PurchasingService.IS_SANDBOX_MODE + "IS_SANDBOX_MODE");
}
Also used : PurchasingListener(com.amazon.device.iap.PurchasingListener)

Example 3 with PurchasingListener

use of com.amazon.device.iap.PurchasingListener in project zype-firebuilder by zype.

the class AmazonInAppPurchaseTest method testCreatePurchasingListener.

@Test
public void testCreatePurchasingListener() {
    AmazonInAppPurchase purchase = new AmazonInAppPurchase();
    IPurchase.PurchaseListener listener = mock(IPurchase.PurchaseListener.class);
    PurchasingListener iapListener = purchase.createIapPurchasingListener(listener);
    iapListener.onUserDataResponse(createUserDataResponse());
    verify(listener).onGetUserDataResponse(any(Response.class), any(UserData.class));
    iapListener.onProductDataResponse(createProductDataResponse());
    verify(listener).onProductDataResponse(any(Response.class), Matchers.anyMapOf(String.class, com.amazon.purchase.model.Product.class), Matchers.anySetOf(String.class));
    iapListener.onPurchaseResponse(createPurchaseResponse());
    verify(listener).onPurchaseResponse(any(Response.class), any(String.class), any(Receipt.class), any(UserData.class));
    iapListener.onPurchaseUpdatesResponse(createPurchaseUpdateResponse());
    verify(listener).onUserDataResponse(any(Response.class), Matchers.anyListOf(Receipt.class), any(UserData.class), any(Boolean.class));
}
Also used : Response(com.amazon.purchase.model.Response) UserDataResponse(com.amazon.device.iap.model.UserDataResponse) ProductDataResponse(com.amazon.device.iap.model.ProductDataResponse) PurchaseUpdatesResponse(com.amazon.device.iap.model.PurchaseUpdatesResponse) PurchaseResponse(com.amazon.device.iap.model.PurchaseResponse) PurchasingListener(com.amazon.device.iap.PurchasingListener) Receipt(com.amazon.purchase.model.Receipt) UserData(com.amazon.purchase.model.UserData) Product(com.amazon.device.iap.model.Product) IPurchase(com.amazon.purchase.IPurchase) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with PurchasingListener

use of com.amazon.device.iap.PurchasingListener in project OneSignal-Android-SDK by OneSignal.

the class TrackAmazonPurchase method checkListener.

void checkListener() {
    if (!canTrack)
        return;
    try {
        PurchasingListener curPurchasingListener = (PurchasingListener) listenerHandlerField.get(listenerHandlerObject);
        if (curPurchasingListener != osPurchasingListener) {
            osPurchasingListener.orgPurchasingListener = curPurchasingListener;
            setListener();
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : PurchasingListener(com.amazon.device.iap.PurchasingListener)

Aggregations

PurchasingListener (com.amazon.device.iap.PurchasingListener)4 ProductDataResponse (com.amazon.device.iap.model.ProductDataResponse)2 PurchaseResponse (com.amazon.device.iap.model.PurchaseResponse)2 PurchaseUpdatesResponse (com.amazon.device.iap.model.PurchaseUpdatesResponse)2 UserDataResponse (com.amazon.device.iap.model.UserDataResponse)2 Receipt (com.amazon.purchase.model.Receipt)2 Response (com.amazon.purchase.model.Response)2 UserData (com.amazon.purchase.model.UserData)2 Product (com.amazon.device.iap.model.Product)1 IPurchase (com.amazon.purchase.IPurchase)1 Product (com.amazon.purchase.model.Product)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1