@Override public void disconnected(GdxPayException exception) { observer.handleInstallError(new GdxPayException("Failed to bind to service", exception)); } });
@Override public void run() { // it might happen that this was already disposed until the service connection was established if (PurchaseManagerGoogleBilling.this.observer == null) return; if (!serviceConnected) PurchaseManagerGoogleBilling.this.observer.handleInstallError( new GdxPayException("Connection to Play Billing not possible")); else if (autoFetchInformation) { fetchOfferDetails(); } else setInstalledAndNotifyObserver(); } });
/** Installs a purchase observer. * * @param autoFetchInformation tells PurchaseManager to automatically fetch offer details on setup to make * {@link PurchaseSystem#getInformation(String)} work properly **/ public static void install (PurchaseObserver observer, PurchaseManagerConfig config, boolean autoFetchInformation) { if (hasManager()) { manager.install(observer, config, autoFetchInformation); } else { observer.handleInstallError(new RuntimeException("No purchase manager was available.")); } }
@Override public void didFail (SKRequest request, NSError error) { log(LOGTYPEERROR, "Error requesting products: " + (error != null ? error.toString() : "unknown")); // Products request failed (likely due to insuficient network connection). observer.handleInstallError(new RuntimeException("Error requesting products: " + (error != null ? error.toString() : "unknown"))); } }
@Override public void requestDidFailWithError(SKRequest request, NSError error) { log(LOGTYPEERROR, "Error requesting products: " + (error != null ? error.toString() : "unknown")); // Products request failed (likely due to insuficient network connection). observer.handleInstallError(new RuntimeException("Error requesting products: " + (error != null ? error.toString() : "unknown"))); } }
@Override public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) { // it might happen that this was already disposed until the response comes back if (observer == null || Gdx.app == null) return; if (responseCode != BillingClient.BillingResponse.OK) { Gdx.app.error(TAG, "onSkuDetailsResponse failed, error code is " + responseCode); if (!installationComplete) observer.handleInstallError(new FetchItemInformationException( String.valueOf(responseCode))); } else { if (skuDetailsList != null) { for (SkuDetails skuDetails : skuDetailsList) { informationMap.put(skuDetails.getSku(), convertSkuDetailsToInformation (skuDetails)); } } setInstalledAndNotifyObserver(); } } });
@Test public void shouldCallObserverInstallErrorOnConnectFailure() throws Exception { requestPurchaseMangerInstallWithFullEditionOffer(); verify(googleInAppBillingService).requestConnect(connectResultListenerArgumentCaptor.capture()); connectResultListenerArgumentCaptor.getValue() .disconnected(new GdxPayException("Disconnected", new SecurityException("Test"))); verify(purchaseObserver).handleInstallError(isA(GdxPayException.class)); }
Gdx.app.error(TAG, "onProductDataResponse: failed, should retry request"); if (!productDataRetrieved) { observer.handleInstallError(new FetchItemInformationException(String.valueOf(status)));
/** * @param autoFetchInformation is not used, because without product information on ios it's not possible to fill * {@link Transaction} object on successful purchase **/ @Override public void install (PurchaseObserver observer, PurchaseManagerConfig config, boolean autoFetchInformation) { this.observer = observer; this.config = config; log(LOGTYPELOG, "Installing purchase observer..."); // Check if the device is configured for purchases. if (SKPaymentQueue.canMakePayments()) { // Create string set from offer identifiers. int size = config.getOfferCount(); Set<String> productIdentifiers = new HashSet<String>(size); for (int i = 0; i < size; i++) { productIdentifiers.add(config.getOffer(i).getIdentifierForStore(PurchaseManagerConfig.STORE_NAME_IOS_APPLE)); } // Request configured offers/products. log(LOGTYPELOG, "Requesting products..."); productsRequest = new SKProductsRequest(productIdentifiers); productsRequest.setDelegate(new IosFetchProductsAndInstallDelegate()); productsRequest.start(); } else { log(LOGTYPEERROR, "Error setting up in-app-billing: Device not configured for purchases!"); observer.handleInstallError(new RuntimeException( "Error installing purchase observer: Device not configured for purchases!")); } }
log(LOGTYPEERROR, "Error setting up in-app-billing: Device not configured for " + "purchases!"); observer.handleInstallError(new RuntimeException("Error installing purchase observer:" + " Device not configured for purchases!"));
/** * This is the callback for {@link PurchasingService#getUserData}. */ @Override public void onUserDataResponse(final UserDataResponse response) { final UserDataResponse.RequestStatus status = response.getRequestStatus(); Gdx.app.log(TAG, "onGetUserDataResponse: requestId (" + response.getRequestId() + ") userIdRequestStatus: " + status + ")"); switch (status) { case SUCCESSFUL: UserData userData = response.getUserData(); Gdx.app.log(TAG, "onUserDataResponse: get user id (" + userData.getUserId() + "), marketplace (" + userData.getMarketplace() + ") "); updateUserData(userData); notifyObserverWhenInstalled(); break; case FAILED: case NOT_SUPPORTED: Gdx.app.error(TAG, "onUserDataResponse failed, status code is " + status); updateUserData(null); observer.handleInstallError(new GdxPayException("onUserDataResponse failed, status code is " + status)); break; } }