google-api-php-client icon indicating copy to clipboard operation
google-api-php-client copied to clipboard

Can't get a purchase state for multy product order.

Open srgbsv opened this issue 1 year ago • 1 comments

Hello

I made purchase, which included several inapp products. Then when I try to get a purchase state using API purchase.products.get, I retrieve correct answer only for first productId from my order. For another products from order I get error:

{
  "error": {
    "code": 400,
    "message": "The purchase token does not match the product ID.",
    "errors": [
     {
       "message": "The purchase token does not match the product ID.",
        "domain": "androidpublisher",
        "reason": "purchaseTokenDoesNotMatchProductId",
        "location": "token",
        "locationType": "parameter"
      }
    ]
  }
}

Steps to reproduce:

  1. Make purchase
List<BillingFlowParams.ProductDetailsParams> params = new ArrayList<>();
// One product
params.add(BillingFlowParams.ProductDetailsParams
                    .newBuilder()
                    .setProductDetails(<ProducetDetails1>)
                    .setOfferToken(<OfferToken>)
                    .build()
);
// Another product
params.add(BillingFlowParams.ProductDetailsParams
                    .newBuilder()
                    .setProductDetails(<ProducetDetails2>)
                    .setOfferToken(<OfferToken>)
                    .build()
);

BillingFlowParams.Builder flowParams = BillingFlowParams.newBuilder()
                    .setProductDetailsParamsList(params);
billingClient.launchBillingFlow(activity, flowParams.build());     
  1. Try to get info about about purchase by token and productId
$androidpublisherService = new \Google_Service_AndroidPublisher($this->client);
$optParams = [];

$products = $androidpublisherService->purchases_products;
$data = $products->get(<bundleId>, <productId>, <token>, $optParams);

On this step for first product in order you will get some sing like this:

Google\Service\AndroidPublisher\ProductPurchase Object
(
    [acknowledgementState] => 1
    [consumptionState] => 1
    [developerPayload] => 
    [kind] => androidpublisher#productPurchase
    [obfuscatedExternalAccountId] => ced18ce3c8becf155b2d9b0093ce92c8
    [obfuscatedExternalProfileId] => 
    [orderId] => GPA.3378-4458-8632-41646
    [productId] => 
    [purchaseState] => 0
    [purchaseTimeMillis] => 1690814498887
    [purchaseToken] => 
    [purchaseType] => 0
    [quantity] => 
    [regionCode] => RU
    [internal_gapi_mappings:protected] => Array
        (
        )

    [modelData:protected] => Array
        (
        )

    [processed:protected] => Array
        (
        )
)

for another you will get the error

Thanks a lot in advance!

Environment details

  • OS: ubuntu 22.04
  • PHP version: 7.4
  • Package name and version: "google/apiclient": "2.14"

srgbsv avatar Aug 08 '23 08:08 srgbsv

I would try to make the call using the APIs Explorer. If you see the same issue there, then the problem is with the productId and token you're provided. If not, then the issue is with this library.

bshaffer avatar Nov 17 '23 17:11 bshaffer

Closing due to inactivity. Please reopen or file a new issue if you have additional questions or concerns.

bshaffer avatar May 20 '24 16:05 bshaffer