Checkout API Setup Guide references commands that

2019-08-22 18:00发布

问题:

The following code snippets in the Checkout API Setup Guide at

https://docs.connect.squareup.com/payments/checkout/setup references GetID()

cause the page to fail and are not in the API:

$checkoutId = $result->getId();

AND

$checkoutUrl = $result->getCheckoutPageUrl();

In fact, I cannot find reference to those commands anywhere in the technical docs or API reference except on the Setup Guide.

Is the Setup Guide wrong or am I missing something? Is Checkout not fully live? I am not sure why a setup example would not be more supported or reference existing documentation.

Update: In the file provided with the SDK, the file Checkout.md describes that getId() and getCheckoutPageUrl() are getters for protected properties:

Note: All properties are protected and only accessed via getters and setters.

I get that... they just don't seem to work.

回答1:

Check out the Square PHP SDK documentation on GitHub. Looks like there might be a mistake in that document, I think the code you want is something like:

(they key missing part being a ->getCheckout()

try {
    $result = $checkoutClient->createCheckout(
      $locationId,
      $checkout
    );
    //Save the checkout ID for verifying transactions
    $checkoutId = $result->getCheckout()->getId();
    //Get the checkout URL that opens the checkout page.
    $checkoutUrl = $result->getCheckout()->getCheckoutPageUrl();
    print_r('Complete your transaction: ' + $checkoutUrl);
} catch (Exception $e) {
    echo 'Exception when calling CheckoutApi->createCheckout: ', $e->getMessage(), PHP_EOL;
}

Let me know if that doesn't work for you.