Skip to content

Commit

Permalink
Merge pull request #136 from square/release/37.1.1.20240717
Browse files Browse the repository at this point in the history
Generated PR for Release: 37.1.1.20240717
  • Loading branch information
jessdelacruzsantos authored Jul 17, 2024
2 parents 447f0a2 + 4c6bf4e commit b3d30e6
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 62 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions doc/apis/apple-pay.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
24 changes: 12 additions & 12 deletions doc/apis/invoices.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions doc/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The following parameters are configurable for the API Client:

| Parameter | Type | Description |
| --- | --- | --- |
| `squareVersion` | `string` | Square Connect API versions<br>*Default*: `'2024-06-04'` |
| `squareVersion` | `string` | Square Connect API versions<br>*Default*: `'2024-07-17'` |
| `customUrl` | `string` | Sets the base URL requests are made to. Defaults to `https://connect.squareup.com`<br>*Default*: `'https://connect.squareup.com'` |
| `environment` | `string` | The API environment. <br> **Default: `production`** |
| `timeout` | `int` | Timeout for API calls in seconds.<br>*Default*: `60` |
Expand All @@ -30,7 +30,7 @@ $client = SquareClientBuilder::init()
'AccessToken'
)
)
->squareVersion('2024-06-04')
->squareVersion('2024-07-17')
->environment('production')
->customUrl('https://connect.squareup.com')
->build();
Expand Down Expand Up @@ -60,7 +60,7 @@ $client = SquareClientBuilder::init()
'AccessToken'
)
)
->squareVersion('2024-06-04')
->squareVersion('2024-07-17')
->build();

$apiResponse = $client->getLocationsApi()->listLocations();
Expand Down
13 changes: 8 additions & 5 deletions doc/models/update-invoice-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<br>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<br>provide `idempotency_key` (or provide an empty string as the value), the endpoint<br>treats each request as independent.<br><br>For more information, see [Idempotency](https://developer.squareup.com/docs/build-basics/common-api-patterns/idempotency).<br>**Constraints**: *Maximum Length*: `128` | getIdempotencyKey(): ?string | setIdempotencyKey(?string idempotencyKey): void |
| `fieldsToClear` | `?(string[])` | Optional | The list of fields to clear.<br>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<br>recommend using null values or the `remove` field when possible. For examples, see<br>[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"
}
Expand All @@ -47,7 +45,12 @@ Describes a `UpdateInvoice` request.
"sublocality": "sublocality6"
}
}
}
},
"fields_to_clear": [
"fields_to_clear1",
"fields_to_clear2",
"fields_to_clear3"
]
}
```

13 changes: 8 additions & 5 deletions src/Apis/ApplePayApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
12 changes: 4 additions & 8 deletions src/Apis/InvoicesApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 10 additions & 10 deletions src/Authentication/BearerAuthManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,27 +15,26 @@
*/
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;
}

/**
* String value for accessToken.
*/
public function getAccessToken(): string
{
return $this->accessToken;
return $this->config['accessToken'] ?? ConfigurationDefaults::ACCESS_TOKEN;
}

/**
Expand All @@ -44,6 +44,6 @@ public function getAccessToken(): string
*/
public function equals(string $accessToken): bool
{
return $accessToken == $this->accessToken;
return $accessToken == $this->getAccessToken();
}
}
2 changes: 1 addition & 1 deletion src/ConfigurationDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down
18 changes: 9 additions & 9 deletions src/Models/UpdateInvoiceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
*
Expand All @@ -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
{
Expand Down
8 changes: 3 additions & 5 deletions src/SquareClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -322,7 +320,7 @@ public function withConfiguration(array $config): self
*/
public function getSdkVersion(): string
{
return '37.1.0.20240604';
return '37.1.1.20240717';
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/Flows/WebhooksHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit b3d30e6

Please sign in to comment.