diff --git a/composer.json b/composer.json index 1654452d..54bcdf91 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "square/square", "description": "Use Square APIs to manage and run business including payment, customer, product, inventory, and employee management.", - "version": "37.1.0.20240604", + "version": "37.1.1.20240717", "type": "library", "keywords": [ "Square", @@ -24,7 +24,7 @@ "ext-json": "*", "apimatic/unirest-php": "^4.0.0", "apimatic/core-interfaces": "~0.1.5", - "apimatic/core": "~0.3.9" + "apimatic/core": "~0.3.11" }, "require-dev": { "squizlabs/php_codesniffer": "^3.5", diff --git a/doc/apis/apple-pay.md b/doc/apis/apple-pay.md index 53649249..9f9f608f 100644 --- a/doc/apis/apple-pay.md +++ b/doc/apis/apple-pay.md @@ -18,8 +18,11 @@ an Apple Pay enabled domain. This endpoint provides an easy way for platform developers to bulk activate Apple Pay on the Web with Square for merchants using their platform. -Note: The SqPaymentForm library is deprecated as of May 13, 2021, and will only receive critical security updates until it is retired on October 31, 2022. -You must migrate your payment form code to the Web Payments SDK to continue using your domain for Apple Pay. For more information on migrating to the Web Payments SDK, see [Migrate to the Web Payments SDK](https://developer.squareup.com/docs/web-payments/migrate). +Note: You will need to host a valid domain verification file on your domain to support Apple Pay. The +current version of this file is always available at https://app.squareup.com/digital-wallets/apple-pay/apple-developer-merchantid-domain-association, +and should be hosted at `.well_known/apple-developer-merchantid-domain-association` on your +domain. This file is subject to change; we strongly recommend checking for updates regularly and avoiding +long-lived caches that might not keep in sync with the correct file version. To learn more about the Web Payments SDK and how to add Apple Pay, see [Take an Apple Pay Payment](https://developer.squareup.com/docs/web-payments/apple-pay). diff --git a/doc/apis/invoices.md b/doc/apis/invoices.md index 23d88845..1c343b20 100644 --- a/doc/apis/invoices.md +++ b/doc/apis/invoices.md @@ -306,10 +306,10 @@ var_dump($apiResponse->getHeaders()); # Update Invoice -Updates an invoice by modifying fields, clearing fields, or both. For most updates, you can use a sparse -`Invoice` object to add fields or change values and use the `fields_to_clear` field to specify fields to clear. -However, some restrictions apply. For example, you cannot change the `order_id` or `location_id` field and you -must provide the complete `custom_fields` list to update a custom field. Published invoices have additional restrictions. +Updates an invoice. This endpoint supports sparse updates, so you only need +to specify the fields you want to change along with the required `version` field. +Some restrictions apply to updating invoices. For example, you cannot change the +`order_id` or `location_id` field. ```php function updateInvoice(string $invoiceId, UpdateInvoiceRequest $body): ApiResponse @@ -339,17 +339,17 @@ $body = UpdateInvoiceRequestBuilder::init( InvoicePaymentRequestBuilder::init() ->uid('2da7964f-f3d2-4f43-81e8-5aa220bf3355') ->tippingEnabled(false) - ->build() + ->reminders( + [ + InvoicePaymentReminderBuilder::init()->build(), + InvoicePaymentReminderBuilder::init()->build(), + InvoicePaymentReminderBuilder::init()->build() + ] + )->build() ] - ) - ->build() + )->build() ) ->idempotencyKey('4ee82288-0910-499e-ab4c-5d0071dad1be') - ->fieldsToClear( - [ - 'payments_requests[2da7964f-f3d2-4f43-81e8-5aa220bf3355].reminders' - ] - ) ->build(); $apiResponse = $invoicesApi->updateInvoice( diff --git a/doc/client.md b/doc/client.md index 58e35b02..37bfe52d 100644 --- a/doc/client.md +++ b/doc/client.md @@ -5,7 +5,7 @@ The following parameters are configurable for the API Client: | Parameter | Type | Description | | --- | --- | --- | -| `squareVersion` | `string` | Square Connect API versions
*Default*: `'2024-06-04'` | +| `squareVersion` | `string` | Square Connect API versions
*Default*: `'2024-07-17'` | | `customUrl` | `string` | Sets the base URL requests are made to. Defaults to `https://connect.squareup.com`
*Default*: `'https://connect.squareup.com'` | | `environment` | `string` | The API environment.
**Default: `production`** | | `timeout` | `int` | Timeout for API calls in seconds.
*Default*: `60` | @@ -30,7 +30,7 @@ $client = SquareClientBuilder::init() 'AccessToken' ) ) - ->squareVersion('2024-06-04') + ->squareVersion('2024-07-17') ->environment('production') ->customUrl('https://connect.squareup.com') ->build(); @@ -60,7 +60,7 @@ $client = SquareClientBuilder::init() 'AccessToken' ) ) - ->squareVersion('2024-06-04') + ->squareVersion('2024-07-17') ->build(); $apiResponse = $client->getLocationsApi()->listLocations(); diff --git a/doc/models/update-invoice-request.md b/doc/models/update-invoice-request.md index 555cc0f3..ba6701cf 100644 --- a/doc/models/update-invoice-request.md +++ b/doc/models/update-invoice-request.md @@ -13,19 +13,17 @@ Describes a `UpdateInvoice` request. | --- | --- | --- | --- | --- | --- | | `invoice` | [`Invoice`](../../doc/models/invoice.md) | Required | Stores information about an invoice. You use the Invoices API to create and manage
invoices. For more information, see [Invoices API Overview](https://developer.squareup.com/docs/invoices-api/overview). | getInvoice(): Invoice | setInvoice(Invoice invoice): void | | `idempotencyKey` | `?string` | Optional | A unique string that identifies the `UpdateInvoice` request. If you do not
provide `idempotency_key` (or provide an empty string as the value), the endpoint
treats each request as independent.

For more information, see [Idempotency](https://developer.squareup.com/docs/build-basics/common-api-patterns/idempotency).
**Constraints**: *Maximum Length*: `128` | getIdempotencyKey(): ?string | setIdempotencyKey(?string idempotencyKey): void | -| `fieldsToClear` | `?(string[])` | Optional | The list of fields to clear.
For examples, see [Update an Invoice](https://developer.squareup.com/docs/invoices-api/update-invoices). | getFieldsToClear(): ?array | setFieldsToClear(?array fieldsToClear): void | +| `fieldsToClear` | `?(string[])` | Optional | The list of fields to clear. Although this field is currently supported, we
recommend using null values or the `remove` field when possible. For examples, see
[Update an Invoice](https://developer.squareup.com/docs/invoices-api/update-invoices). | getFieldsToClear(): ?array | setFieldsToClear(?array fieldsToClear): void | ## Example (as JSON) ```json { - "fields_to_clear": [ - "payments_requests[2da7964f-f3d2-4f43-81e8-5aa220bf3355].reminders" - ], "idempotency_key": "4ee82288-0910-499e-ab4c-5d0071dad1be", "invoice": { "payment_requests": [ { + "reminders": null, "tipping_enabled": false, "uid": "2da7964f-f3d2-4f43-81e8-5aa220bf3355" } @@ -47,7 +45,12 @@ Describes a `UpdateInvoice` request. "sublocality": "sublocality6" } } - } + }, + "fields_to_clear": [ + "fields_to_clear1", + "fields_to_clear2", + "fields_to_clear3" + ] } ``` diff --git a/src/Apis/ApplePayApi.php b/src/Apis/ApplePayApi.php index fcb4ef63..232fd833 100644 --- a/src/Apis/ApplePayApi.php +++ b/src/Apis/ApplePayApi.php @@ -21,11 +21,14 @@ class ApplePayApi extends BaseApi * This endpoint provides an easy way for platform developers to bulk activate * Apple Pay on the Web with Square for merchants using their platform. * - * Note: The SqPaymentForm library is deprecated as of May 13, 2021, and will only receive critical - * security updates until it is retired on October 31, 2022. - * You must migrate your payment form code to the Web Payments SDK to continue using your domain for - * Apple Pay. For more information on migrating to the Web Payments SDK, see [Migrate to the Web - * Payments SDK](https://developer.squareup.com/docs/web-payments/migrate). + * Note: You will need to host a valid domain verification file on your domain to support Apple Pay. + * The + * current version of this file is always available at https://app.squareup.com/digital-wallets/apple- + * pay/apple-developer-merchantid-domain-association, + * and should be hosted at `.well_known/apple-developer-merchantid-domain-association` on your + * domain. This file is subject to change; we strongly recommend checking for updates regularly and + * avoiding + * long-lived caches that might not keep in sync with the correct file version. * * To learn more about the Web Payments SDK and how to add Apple Pay, see [Take an Apple Pay * Payment](https://developer.squareup.com/docs/web-payments/apple-pay). diff --git a/src/Apis/InvoicesApi.php b/src/Apis/InvoicesApi.php index 38418f67..085fc1e6 100644 --- a/src/Apis/InvoicesApi.php +++ b/src/Apis/InvoicesApi.php @@ -153,14 +153,10 @@ public function getInvoice(string $invoiceId): ApiResponse } /** - * Updates an invoice by modifying fields, clearing fields, or both. For most updates, you can use a - * sparse - * `Invoice` object to add fields or change values and use the `fields_to_clear` field to specify - * fields to clear. - * However, some restrictions apply. For example, you cannot change the `order_id` or `location_id` - * field and you - * must provide the complete `custom_fields` list to update a custom field. Published invoices have - * additional restrictions. + * Updates an invoice. This endpoint supports sparse updates, so you only need + * to specify the fields you want to change along with the required `version` field. + * Some restrictions apply to updating invoices. For example, you cannot change the + * `order_id` or `location_id` field. * * @param string $invoiceId The ID of the invoice to update. * @param UpdateInvoiceRequest $body An object containing the fields to POST for the request. diff --git a/src/Authentication/BearerAuthManager.php b/src/Authentication/BearerAuthManager.php index aac2b4f4..0416449d 100644 --- a/src/Authentication/BearerAuthManager.php +++ b/src/Authentication/BearerAuthManager.php @@ -5,6 +5,7 @@ namespace Square\Authentication; use Core\Authentication\CoreAuth; +use Square\ConfigurationDefaults; use Core\Request\Parameters\HeaderParam; use Core\Utils\CoreHelper; use Square\BearerAuthCredentials; @@ -14,19 +15,18 @@ */ class BearerAuthManager extends CoreAuth implements BearerAuthCredentials { - private $accessToken; - /** - * Returns an instance of this class. - * - * @param string $accessToken The OAuth 2.0 Access Token to use for API requests. + * @var array */ - public function __construct(string $accessToken) + private $config; + + public function __construct(array $config) { + $this->config = $config; parent::__construct( - HeaderParam::init('Authorization', CoreHelper::getBearerAuthString($accessToken))->requiredNonEmpty() + HeaderParam::init('Authorization', CoreHelper::getBearerAuthString($this->getAccessToken())) + ->requiredNonEmpty() ); - $this->accessToken = $accessToken; } /** @@ -34,7 +34,7 @@ public function __construct(string $accessToken) */ public function getAccessToken(): string { - return $this->accessToken; + return $this->config['accessToken'] ?? ConfigurationDefaults::ACCESS_TOKEN; } /** @@ -44,6 +44,6 @@ public function getAccessToken(): string */ public function equals(string $accessToken): bool { - return $accessToken == $this->accessToken; + return $accessToken == $this->getAccessToken(); } } diff --git a/src/ConfigurationDefaults.php b/src/ConfigurationDefaults.php index e13834f0..53f66261 100644 --- a/src/ConfigurationDefaults.php +++ b/src/ConfigurationDefaults.php @@ -27,7 +27,7 @@ class ConfigurationDefaults public const HTTP_METHODS_TO_RETRY = ['GET', 'PUT']; - public const SQUARE_VERSION = '2024-06-04'; + public const SQUARE_VERSION = '2024-07-17'; public const ADDITIONAL_HEADERS = []; diff --git a/src/Models/UpdateInvoiceRequest.php b/src/Models/UpdateInvoiceRequest.php index 92ca29fd..cf7b6fd2 100644 --- a/src/Models/UpdateInvoiceRequest.php +++ b/src/Models/UpdateInvoiceRequest.php @@ -108,9 +108,9 @@ public function unsetIdempotencyKey(): void /** * Returns Fields to Clear. - * The list of fields to clear. - * For examples, see [Update an Invoice](https://developer.squareup.com/docs/invoices-api/update- - * invoices). + * The list of fields to clear. Although this field is currently supported, we + * recommend using null values or the `remove` field when possible. For examples, see + * [Update an Invoice](https://developer.squareup.com/docs/invoices-api/update-invoices). * * @return string[]|null */ @@ -124,9 +124,9 @@ public function getFieldsToClear(): ?array /** * Sets Fields to Clear. - * The list of fields to clear. - * For examples, see [Update an Invoice](https://developer.squareup.com/docs/invoices-api/update- - * invoices). + * The list of fields to clear. Although this field is currently supported, we + * recommend using null values or the `remove` field when possible. For examples, see + * [Update an Invoice](https://developer.squareup.com/docs/invoices-api/update-invoices). * * @maps fields_to_clear * @@ -139,9 +139,9 @@ public function setFieldsToClear(?array $fieldsToClear): void /** * Unsets Fields to Clear. - * The list of fields to clear. - * For examples, see [Update an Invoice](https://developer.squareup.com/docs/invoices-api/update- - * invoices). + * The list of fields to clear. Although this field is currently supported, we + * recommend using null values or the `remove` field when possible. For examples, see + * [Update an Invoice](https://developer.squareup.com/docs/invoices-api/update-invoices). */ public function unsetFieldsToClear(): void { diff --git a/src/SquareClient.php b/src/SquareClient.php index 074929f2..11478ae6 100644 --- a/src/SquareClient.php +++ b/src/SquareClient.php @@ -158,16 +158,14 @@ class SquareClient implements ConfigurationInterface public function __construct(array $config = []) { $this->config = array_merge(ConfigurationDefaults::_ALL, CoreHelper::clone($config)); - $this->bearerAuthManager = new BearerAuthManager( - $this->config['accessToken'] ?? ConfigurationDefaults::ACCESS_TOKEN - ); + $this->bearerAuthManager = new BearerAuthManager($this->config); $this->validateConfig(); $this->client = ClientBuilder::init(new HttpClient(Configuration::init($this))) ->converter(new CompatibilityConverter()) ->jsonHelper(ApiHelper::getJsonHelper()) ->apiCallback($this->config['httpCallback'] ?? null) ->userAgent( - 'Square-PHP-SDK/37.1.0.20240604 ({api-version}) {engine}/{engine-version} ({os-' . + 'Square-PHP-SDK/37.1.1.20240717 ({api-version}) {engine}/{engine-version} ({os-' . 'info}) {detail}' ) ->userAgentConfig( @@ -322,7 +320,7 @@ public function withConfiguration(array $config): self */ public function getSdkVersion(): string { - return '37.1.0.20240604'; + return '37.1.1.20240717'; } /** diff --git a/tests/Flows/WebhooksHelperTest.php b/tests/Flows/WebhooksHelperTest.php index bf9f6c39..dd7e6e54 100644 --- a/tests/Flows/WebhooksHelperTest.php +++ b/tests/Flows/WebhooksHelperTest.php @@ -22,6 +22,22 @@ public function testSignatureValidationPass(): void $this->assertTrue($isValid); } + public function testEscapedCharactersPass(): void + { + $specialRequestBody = '{"data":{"type":"webhooks","id":">id<"}}'; + $escapedSignatureHeader = 'Cxt7+aTi4rKgcA0bC4g9EHdVtLSDWdqccmL5MvihU4U='; + $defaultSignatureKey = 'signature-key'; + $defaultNotificationUrl = 'https://webhook.site/webhooks'; + + $isValid = WebhooksHelper::isValidWebhookEventSignature( + $specialRequestBody, + $escapedSignatureHeader, + $defaultSignatureKey, + $defaultNotificationUrl + ); + $this->assertTrue($isValid); + } + public function testSignatureValidationFailsOnNotificationUrlMismatch(): void { $isValid = WebhooksHelper::isValidWebhookEventSignature(