diff --git a/README.md b/README.md index 7843f12..c8cf8d0 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ A `cURL error 60` means PHP cannot find a CA bundle that trusts the API certific All the API responses that do not fall in the 2** status codes, the SDK will throw a `CheckoutApiException`. -The exception encapsulates `http_metadata` and `$error_details`, if available. +The exception encapsulates `http_metadata` (status, reason phrase and response headers, cookies excluded) and `$error_details`, if available. A request argument that cannot be sent as given (for example an empty id, or a query filter value that is not a string, number, boolean or `DateTime`) throws a `CheckoutArgumentException` before any request is sent. Both exceptions extend `CheckoutException`: catch `CheckoutException` to handle the two. diff --git a/lib/Checkout/ApiClient.php b/lib/Checkout/ApiClient.php index 3e702ff..70e076d 100644 --- a/lib/Checkout/ApiClient.php +++ b/lib/Checkout/ApiClient.php @@ -207,7 +207,7 @@ private function submit( string $multipart ): array { try { - $this->logger->info("POST " . $path . " file: " . $fileRequest->file); + $this->logger->info("POST " . $path); $headers = $this->getHeaders($authorization, null, null); // Provide a stream with explicit size so Guzzle can set Content-Length correctly. @@ -234,11 +234,12 @@ private function submit( ]); return $this->getResponseContents($response); } catch (\Throwable $e) { - $this->logger->error($path . " error: " . CheckoutUtils::describeFailure($e)); + $description = CheckoutUtils::describeFailure($e); + $this->logger->error($path . " error: " . $description); if ($e instanceof RequestException) { throw CheckoutApiException::from($e); } - throw new CheckoutApiException(CheckoutUtils::describeFailure($e)); + throw new CheckoutApiException($description); } } @@ -298,11 +299,12 @@ private function invoke( ]); return $this->getResponseContents($response); } catch (\Throwable $e) { - $this->logger->error($path . " error: " . CheckoutUtils::describeFailure($e)); + $description = CheckoutUtils::describeFailure($e); + $this->logger->error($path . " error: " . $description); if ($e instanceof RequestException) { throw CheckoutApiException::from($e); } - throw new CheckoutApiException(CheckoutUtils::describeFailure($e)); + throw new CheckoutApiException($description); } } diff --git a/lib/Checkout/CheckoutApiException.php b/lib/Checkout/CheckoutApiException.php index 43a60aa..860a748 100644 --- a/lib/Checkout/CheckoutApiException.php +++ b/lib/Checkout/CheckoutApiException.php @@ -3,37 +3,94 @@ namespace Checkout; use GuzzleHttp\Exception\RequestException; +use Psr\Http\Message\ResponseInterface; class CheckoutApiException extends CheckoutException { /** - * @var array + * @var array|string|int|float|bool|null the decoded JSON body of the response, usually an + * array (a JSON scalar decodes to its value); an empty array when there is no response or + * its body cannot be read, null when the body is not JSON */ public $error_details; /** - * @var HttpMetadata + * @var HttpMetadata|null the reason phrase, status code, headers (cookies excluded) and + * protocol version of the response; null when there is none or it cannot be read */ public $http_metadata; /** - * @param RequestException $requestException - * @return CheckoutApiException + * @param RequestException $requestException a failed request of the HTTP client + * @return CheckoutApiException with the response status in its message, or the failure's own + * code when there is no readable response (0 for the HTTP client's own errors), the + * response body in error_details and the response metadata in http_metadata */ public static function from( #[\SensitiveParameter] RequestException $requestException ) { - $response = $requestException->getResponse(); - + $response = CheckoutUtils::responseOf($requestException); + $status = CheckoutUtils::statusOf($response); + if ($status === null) { + $code = $requestException->getCode(); + $status = is_int($code) ? $code : 0; + } $ex = new CheckoutApiException(sprintf( - "The API response status code (%s) does not indicate success.", - $requestException->getCode() + "The API response status code (%d) does not indicate success.", + $status )); - $ex->error_details = isset($response) - ? json_decode($response->getBody()->getContents(), true) - : []; - $ex->http_metadata = CheckoutUtils::getHttpMetadata($response); - + $body = CheckoutUtils::bodyOf($response); + $ex->error_details = $body === null ? [] : json_decode($body, true); + $ex->http_metadata = self::metadataWithoutCookies($response); return $ex; } + + /** + * Builds the metadata of a failed response, without its cookies. + * + * @param ResponseInterface|null $response the response of the failed request, if any + * @return HttpMetadata|null the reason phrase, status code, headers without Set-Cookie and + * protocol version; null when there is no response or it cannot be read + */ + private static function metadataWithoutCookies( + #[\SensitiveParameter] + ?ResponseInterface $response + ) { + if ($response === null) { + return null; + } + try { + $headers = array_filter($response->getHeaders(), function ($name) { + return !in_array(self::plainHeaderName($name), ["set-cookie", "set-cookie2"], true); + }, ARRAY_FILTER_USE_KEY); + $reason = $response->getReasonPhrase(); + $status = $response->getStatusCode(); + $protocol = $response->getProtocolVersion(); + // Implementations without return types (psr/http-message 1.0) may return anything. + if (!is_string($reason) || !is_int($status) || !is_string($protocol)) { + return null; + } + return new HttpMetadata($reason, $status, $headers, $protocol); + } catch (\Throwable $unreadable) { + return null; + } + } + + /** + * @param mixed $name a header name + * @return string the name in lower case with only its letters, digits and hyphens, so padding, + * control or format characters that a lenient PSR-7 implementation leaves in it do not hide + * which header it is + */ + private static function plainHeaderName($name) + { + $plain = ""; + foreach (str_split(strtolower((string)$name)) as $character) { + if (($character >= "a" && $character <= "z") || ($character >= "0" && $character <= "9") + || $character === "-") { + $plain .= $character; + } + } + return $plain; + } } diff --git a/lib/Checkout/CheckoutUtils.php b/lib/Checkout/CheckoutUtils.php index 14342d7..05c9450 100644 --- a/lib/Checkout/CheckoutUtils.php +++ b/lib/Checkout/CheckoutUtils.php @@ -5,6 +5,7 @@ use DateTime; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\Response; +use Psr\Http\Message\ResponseInterface; class CheckoutUtils { @@ -97,6 +98,79 @@ public static function getHttpMetadata(?Response $http_response = null): ?HttpMe ); } + /** + * The response of an HTTP client failure. For internal use by the SDK. + * + * @internal + * @param \Throwable $failure any failure; only HTTP client request failures have a response + * @return ResponseInterface|null null when the failure has no response or it cannot be read + */ + public static function responseOf( + #[\SensitiveParameter] + \Throwable $failure + ): ?ResponseInterface { + if (!$failure instanceof RequestException) { + return null; + } + try { + return $failure->getResponse(); + } catch (\Throwable $unreadable) { + return null; + } + } + + /** + * The status code of a response. For internal use by the SDK. + * + * @internal + * @param ResponseInterface|null $response the response to read, if any + * @return int|null null when there is no response or its status cannot be read + */ + public static function statusOf( + #[\SensitiveParameter] + ?ResponseInterface $response + ): ?int { + if ($response === null) { + return null; + } + try { + $status = $response->getStatusCode(); + } catch (\Throwable $unreadable) { + return null; + } + return is_int($status) ? $status : null; + } + + /** + * The body of a response: all of it when the stream is seekable, otherwise what remains + * unread. For internal use by the SDK. + * + * @internal + * @param ResponseInterface|null $response the response to read, if any + * @return string|null null when there is no response or its body cannot be read + */ + public static function bodyOf( + #[\SensitiveParameter] + ?ResponseInterface $response + ): ?string { + if ($response === null) { + return null; + } + // Read with rewind() and getContents(), not __toString(): an exception thrown inside + // __toString() cannot be caught before PHP 7.4, on the lines that share this code. + try { + $body = $response->getBody(); + if ($body->isSeekable()) { + $body->rewind(); + } + $contents = $body->getContents(); + } catch (\Throwable $unreadable) { + return null; + } + // Only text is returned: converting another value could call a __toString() that throws. + return is_string($contents) ? $contents : null; + } + /** * Describes a failure for an SDK error message or log line without copying text the SDK does * not control. For internal use by the SDK. @@ -123,8 +197,9 @@ public static function describeFailure( if ($failure instanceof CheckoutException && strpos($failure->getFile(), __DIR__ . DIRECTORY_SEPARATOR) === 0) { return $class . ": " . $failure->getMessage(); } - if ($failure instanceof RequestException && $failure->getResponse() !== null) { - return $class . " (status " . $failure->getResponse()->getStatusCode() . ")"; + $status = self::statusOf(self::responseOf($failure)); + if ($status !== null) { + return $class . " (status " . $status . ")"; } // Transfer errors of the HTTP client carry the transport error number in their context. if (method_exists($failure, "getHandlerContext")) { diff --git a/lib/Checkout/OAuthSdkCredentials.php b/lib/Checkout/OAuthSdkCredentials.php index 0d42179..40b40d3 100644 --- a/lib/Checkout/OAuthSdkCredentials.php +++ b/lib/Checkout/OAuthSdkCredentials.php @@ -4,7 +4,6 @@ use DateInterval; use DateTime; -use GuzzleHttp\Exception\RequestException; class OAuthSdkCredentials implements SdkCredentialsInterface { @@ -124,10 +123,10 @@ private function getAccessToken() "scope" => implode(" ", $this->scopes) ] ]); + $body = json_decode((string)$response->getBody(), true); } catch (\Throwable $e) { throw new CheckoutException(self::tokenFailureMessage($e)); } - $body = json_decode((string)$response->getBody(), true); if (!self::isValidTokenResponse($body)) { throw CheckoutAuthorizationException::invalidAccessTokenResponse(); } @@ -144,19 +143,22 @@ private function getAccessToken() * failed token request; otherwise a description of the failure. No text of the response or * of another library is copied. */ - private static function tokenFailureMessage(\Throwable $failure) - { - if ($failure instanceof RequestException && $failure->getResponse() !== null) { - $response = $failure->getResponse(); - $message = "OAuth token request failed with status " . $response->getStatusCode(); - $body = json_decode((string)$response->getBody(), true); - $error = is_array($body) ? ($body["error"] ?? null) : null; - if (is_string($error) && in_array($error, self::OAUTH_ERROR_CODES, true)) { - $message .= " (" . $error . ")"; - } - return $message; + private static function tokenFailureMessage( + #[\SensitiveParameter] + \Throwable $failure + ) { + $response = CheckoutUtils::responseOf($failure); + $status = CheckoutUtils::statusOf($response); + if ($status === null) { + return "OAuth token request failed: " . CheckoutUtils::describeFailure($failure); + } + $message = "OAuth token request failed with status " . $status; + $body = json_decode((string)CheckoutUtils::bodyOf($response), true); + $error = is_array($body) ? ($body["error"] ?? null) : null; + if (is_string($error) && in_array($error, self::OAUTH_ERROR_CODES, true)) { + $message .= " (" . $error . ")"; } - return "OAuth token request failed: " . CheckoutUtils::describeFailure($failure); + return $message; } /** diff --git a/test/Checkout/Tests/ErrorHandlingTest.php b/test/Checkout/Tests/ErrorHandlingTest.php index 6d4fdfc..fe92c26 100644 --- a/test/Checkout/Tests/ErrorHandlingTest.php +++ b/test/Checkout/Tests/ErrorHandlingTest.php @@ -38,7 +38,11 @@ use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Request; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Psr7\FnStream; use GuzzleHttp\Psr7\Response; +use GuzzleHttp\Psr7\Utils; +use Psr\Http\Message\ResponseInterface; use Mockery\Adapter\Phpunit\MockeryTestCase; use Monolog\Handler\TestHandler; use Monolog\Logger; @@ -62,6 +66,9 @@ class ErrorHandlingTest extends MockeryTestCase const SESSION_SECRET = "sek_zqsess0123456789abcdef"; const CARDHOLDER_SECRET = "zqcard-0123456789abcdef"; const FORWARD_SECRET = "zqfwd-0123456789abcdef"; + const RESPONSE_COOKIE = "zqcookie-0123456789abcdef"; + const FAILURE_CODE = "zqcode-0123456789abcdef"; + const UPLOAD_NAME = "zqupload-0123456789abcdef"; const ENROLLMENT_SECRET = "zqpw-0123456789abcdef"; const SIGNING_KEY = "zqsig-0123456789abcdef"; const ENCRYPTION_KEY = "zqenc-0123456789abcdef"; @@ -72,7 +79,8 @@ class ErrorHandlingTest extends MockeryTestCase * Markers searched for in every rendering of an error, one per value above. */ const TAGS = [ - "zqcsecret", "zqtoken", "zqskey", "zqprev", "zqsess", "zqcard", "zqfwd", "zqpw", "zqsig", "zqenc", "zqbad", + "zqcsecret", "zqtoken", "zqskey", "zqprev", "zqsess", "zqcard", "zqfwd", "zqpw", "zqsig", "zqenc", + "zqcookie", "zqcode", "zqupload", "zqbad", ]; /** @@ -113,10 +121,14 @@ public static function tokenFailures() "status 401" => [new Response(401, [], '{"error":"invalid_client"}')], "status 400 non-JSON body" => [self::errorPage(400)], "status 403 error page" => [self::errorPage(403, "", "")], + "status 200 body that cannot be read" => [self::unreadableBody(200)], "unreachable" => [new ConnectException("Connection refused", new Request("POST", "https://x"))], "failure with a long message" => [self::failingHandler("plain")], "SDK exception type from the HTTP stack" => [self::failingHandler("sdk")], "SDK exception factory from the HTTP stack" => [self::failingHandler("sdk factory")], + "failure whose response cannot be read" => [self::failingHandler("unreadable response")], + "failure whose body cannot be read" => [self::failingHandler("unreadable body")], + "failure with a text code" => [self::failingHandler("text code")], "failure with an unusual context" => [self::failingHandler("object context")], "failure whose context cannot be read" => [self::failingHandler("failing context")], "error in the HTTP client" => [self::errorInTheHttpClient()], @@ -671,6 +683,152 @@ function (RequestInterface $request) { } } + /** + * @test + */ + public function successfulResponseHeadersAreKeptAsTheyAre() + { + $result = $this->staticKeysApi([new Response(200, [ + "Cko-Request-Id" => "req_123", + "Set-Cookie" => "session=abc", + ], '{"id":"cus_123"}')])->getCustomersClient()->get("cus_123"); + + $this->assertSame(["session=abc"], $result["http_metadata"]->getHeaders()["Set-Cookie"]); + } + + /** + * @test + */ + public function errorMetadataOfAnotherPsr7ResponseIsKeptWithoutCookies() + { + $response = \Mockery::mock(ResponseInterface::class); + $response->shouldReceive("getStatusCode")->andReturn(401); + $response->shouldReceive("getReasonPhrase")->andReturn("Unauthorized"); + $response->shouldReceive("getProtocolVersion")->andReturn("1.1"); + $response->shouldReceive("getBody")->andReturn(Utils::streamFor('{"error_type":"request_unauthorized"}')); + $cookie = ["session=" . self::RESPONSE_COOKIE]; + $response->shouldReceive("getHeaders")->andReturn([ + "Cko-Request-Id" => ["req_123"], + "Set-Cookie" => $cookie, + "Set-Cookie " => $cookie, + "\tSet-Cookie" => $cookie, + "Set-Cookie\0" => $cookie, + "Set-Cookie\r\n" => $cookie, + "Set\u{200B}-Cookie2" => $cookie, + ]); + + $e = $this->failedCustomersCall(function (RequestInterface $request) use ($response) { + throw new RequestException("failed", $request, $response); + }); + + $this->assertSame("The API response status code (401) does not indicate success.", $e->getMessage()); + $this->assertSame(["Cko-Request-Id" => ["req_123"]], $e->http_metadata->getHeaders()); + $this->assertSame(["error_type" => "request_unauthorized"], $e->error_details); + } + + /** + * @test + */ + public function errorMetadataIsLeftEmptyWhenItsHeadersCannotBeRead() + { + $response = new class (401, [], '{"error_type":"request_unauthorized"}') extends Response { + public function getHeaders(): array + { + throw new \RuntimeException("no headers"); + } + }; + + $e = $this->failedCustomersCall(function (RequestInterface $request) use ($response) { + throw new RequestException("failed", $request, $response); + }); + + $this->assertNull($e->http_metadata); + $this->assertSame(["error_type" => "request_unauthorized"], $e->error_details); + } + + /** + * @test + */ + public function errorMessageTakesTheStatusFromTheResponse() + { + $e = $this->failedCustomersCall(function (RequestInterface $request) { + throw new class ("failed", $request, new Response(401)) extends RequestException { + public function __construct($message, RequestInterface $request, ResponseInterface $response) + { + parent::__construct($message, $request, $response); + $this->code = 500; + } + }; + }); + + $this->assertSame("The API response status code (401) does not indicate success.", $e->getMessage()); + } + + /** + * @param callable $handler + * @return CheckoutApiException the error of a customers call answered by the handler + */ + private function failedCustomersCall(callable $handler) + { + try { + $this->staticKeysApi([$handler])->getCustomersClient()->get("cus_123"); + } catch (CheckoutApiException $e) { + return $e; + } + $this->fail("expected an exception"); + } + + /** + * @test + */ + public function uploadLogLineNamesOnlyThePath() + { + // No directory of its own: the mocked client keeps the file open until the test ends, and + // Windows cannot remove a directory that still holds an open file. + $file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "evidence-" . uniqid() . "-" . self::UPLOAD_NAME . ".pdf"; + file_put_contents($file, "%PDF-1.4"); + $apiClient = new ApiClient(new CheckoutConfiguration( + $this->createMock(SdkCredentialsInterface::class), + Environment::sandbox(), + $this->httpClient([new Response(200, [], '{"id":"file_123"}')]), + $this->logger() + )); + $request = new \Checkout\Files\FileRequest(); + $request->file = $file; + $request->purpose = "dispute_evidence"; + + try { + $apiClient->submitFile("files", $request, new SdkAuthorization(PlatformType::$default, self::SECRET_KEY)); + } finally { + unlink($file); + } + + $messages = array_map(function ($record) { + return $record["message"]; + }, $this->logs->getRecords()); + $this->assertSame(["POST files"], $messages); + } + + /** + * @test + */ + public function responseHeadersAreKeptWithoutCookies() + { + $e = $this->failedCustomersCall(function () { + return new Response(422, [ + "Cko-Request-Id" => "req_123", + "Set-Cookie" => "session=" . self::RESPONSE_COOKIE, + "set-cookie2" => "legacy=" . self::RESPONSE_COOKIE, + ], '{"error_type":"request_invalid"}'); + }); + + $headers = array_change_key_case($e->http_metadata->getHeaders(), CASE_LOWER); + $this->assertSame(["req_123"], $headers["cko-request-id"]); + $this->assertArrayNotHasKey("set-cookie", $headers); + $this->assertArrayNotHasKey("set-cookie2", $headers); + $this->assertSame(["error_type" => "request_invalid"], $e->error_details); + } + /** * @test */ @@ -760,6 +918,7 @@ public function everySensitiveParameterIsMarked() "Checkout\\OAuthAccessToken", "Checkout\\Issuing\\CardholderAccessTokens\\CardholderAccessTokenRequest", "GuzzleHttp\\Exception\\RequestException", + "Throwable", "Checkout\\Forward\\Requests\\CreateSecretRequest", "Checkout\\Forward\\Requests\\UpdateSecretRequest", "Checkout\\Forward\\Requests\\ForwardRequest", @@ -823,7 +982,6 @@ public function everySensitiveParameterIsMarked() "Checkout\\ApiClient::isFormUrlEncodedContent" => ["requestBody"], "Checkout\\ApiClient::isMultipartFormData" => ["requestBody"], "Checkout\\Client::createFormUrlEncodedContent" => ["request"], - "Checkout\\CheckoutUtils::describeFailure" => ["failure"], "Checkout\\CheckoutAuthorizationException::invalidAuthorization" => ["authorizationType"], "Checkout\\ApiClient::get" => ["headers"], "Checkout\\ApiClient::post" => ["requestBody", "headers"], @@ -848,6 +1006,7 @@ public function everySensitiveParameterIsMarked() "Checkout\\Sessions\\SessionsClient::completeSession" => ["sessionSecret"], "Checkout\\Sessions\\SessionsClient::updateThreeDsMethodCompletionIndicator" => ["sessionSecret"], "Checkout\\Sessions\\SessionSecretSdkCredentials::__construct" => ["secret"], + "Checkout\\OAuthSdkCredentials::tokenFailureMessage" => ["failure"], ]; $unmarked = []; @@ -994,9 +1153,15 @@ public static function apiFailures() return [ "status 401" => [new Response(401, [], "")], "status 400 error page" => [self::errorPage(400, "", "")], + "status 401 setting a cookie" => [ + new Response(401, ["Set-Cookie" => "session=" . self::RESPONSE_COOKIE . "; Secure"], "") + ], "failure with a long message" => [self::failingHandler("plain")], "SDK exception type from the HTTP stack" => [self::failingHandler("sdk")], "SDK exception factory from the HTTP stack" => [self::failingHandler("sdk factory")], + "failure whose response cannot be read" => [self::failingHandler("unreadable response")], + "failure whose body cannot be read" => [self::failingHandler("unreadable body")], + "failure with a text code" => [self::failingHandler("text code")], "failure with an unusual context" => [self::failingHandler("object context")], "failure whose context cannot be read" => [self::failingHandler("failing context")], "unreachable" => [new ConnectException("Connection refused", new Request("GET", "https://x"))], @@ -1016,9 +1181,28 @@ private static function errorPage(int $status, string $before = "", string $afte }; } + /** + * @return callable a handler that answers with a response whose body fails when read, with a + * message made of the request headers and body + */ + private static function unreadableBody(int $status) + { + return function (RequestInterface $request) use ($status) { + $message = "failed " . json_encode($request->getHeaders()) . " " . (string)$request->getBody(); + $fail = function () use ($message) { + throw new \RuntimeException($message); + }; + $body = FnStream::decorate(Utils::streamFor("{}"), [ + "__toString" => $fail, "getContents" => $fail, "read" => $fail, + ]); + return new Response($status, ["Content-Type" => "application/json"], $body); + }; + } + /** * @param string $kind "plain" (a RuntimeException), "sdk" (a CheckoutException subclass), "sdk - * factory" (an SDK exception built by an SDK factory method), + * factory" (an SDK exception built by an SDK factory method), "unreadable response" or + * "unreadable body" (a RequestException whose response or body cannot be read), * "object context" or "failing context" (a failure whose handler context is not an array or * cannot be read) * @return callable a handler that fails with a message made of the request headers and body @@ -1033,6 +1217,23 @@ private static function failingHandler(string $kind) }; case "sdk factory": throw CheckoutAuthorizationException::invalidAuthorization($message); + case "unreadable response": + throw new class ($message, $request) extends RequestException { + public function getResponse(): ?ResponseInterface + { + throw new \RuntimeException("no response"); + } + }; + case "text code": + throw new class ($message, $request) extends RequestException { + public function __construct($message, RequestInterface $request) + { + parent::__construct($message, $request); + $this->code = ErrorHandlingTest::FAILURE_CODE; + } + }; + case "unreadable body": + throw new RequestException($message, $request, self::unreadableBody(500)($request)); case "object context": throw new class ($message) extends \RuntimeException { public function getHandlerContext() diff --git a/test/Checkout/Tests/OAuthIntegrationTest.php b/test/Checkout/Tests/OAuthIntegrationTest.php index 06519bb..f8ccabe 100644 --- a/test/Checkout/Tests/OAuthIntegrationTest.php +++ b/test/Checkout/Tests/OAuthIntegrationTest.php @@ -4,8 +4,8 @@ use Checkout\CheckoutApiException; use Checkout\CheckoutSdk; +use Checkout\Common\AmountAllocations; use Checkout\Common\Currency; -use Checkout\Common\MarketplaceData; use Checkout\Environment; use Checkout\Payments\Request\PaymentRequest; use Checkout\Payments\Request\Source\RequestCardSource; @@ -44,8 +44,12 @@ public function shouldMakePaymentWithOAuth() $paymentIndividualSender->last_name = "Test"; $paymentIndividualSender->address = $this->getAddress(); - $marketplace = new MarketplaceData(); - $marketplace->sub_entity_id = "ent_ocw5i74vowfg2edpy66izhts2u"; + // The OAuth client's entity must allocate the payment to a sub-entity; the sandbox refuses + // the former marketplace object (marketplace_not_supported) and a payment without an + // allocation (amount_allocations_required). + $allocation = new AmountAllocations(); + $allocation->id = "ent_ocw5i74vowfg2edpy66izhts2u"; + $allocation->amount = 10; $paymentRequest = new PaymentRequest(); $paymentRequest->source = $requestCardSource; @@ -54,8 +58,8 @@ public function shouldMakePaymentWithOAuth() $paymentRequest->amount = 10; $paymentRequest->currency = Currency::$EUR; $paymentRequest->processing_channel_id = "pc_a6dabcfa2o3ejghb3sjuotdzzy"; - $paymentRequest->marketplace = $marketplace; $paymentRequest->sender = $paymentIndividualSender; + $paymentRequest->amount_allocations = array($allocation); $paymentResponse = $this->checkoutApi->getPaymentsClient()->requestPayment($paymentRequest);