googleapis / google-api-php-client

A PHP client library for accessing Google APIs
http://googleapis.github.io/google-api-php-client/
Apache License 2.0
9.32k stars 3.52k forks source link

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

Closed srgbsv closed 4 months ago

srgbsv commented 1 year ago

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());     

2) 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

bshaffer commented 10 months ago

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 commented 4 months ago

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