square-php-sdk icon indicating copy to clipboard operation
square-php-sdk copied to clipboard

Currency is not mapped in the ListPayoutsResponse

Open StApostol opened this issue 2 years ago • 5 comments

Describe the bug The documentation https://developer.squareup.com/reference/square/payouts-api/list-payouts says we get amount_money with currency_code. But when converting, we use the currency field, as a result we have an empty value in the object

Expected behavior The expected result is that the Money object has a filled currency value

Screenshots image

Server raw response image-server

Square SDK version 29.0.0.20230720

StApostol avatar Jul 25 '23 05:07 StApostol

Hey @StApostol

Sorry you're running into issue here, but I'm not quite sure I understand your problem. Why are you trying to access a key called currency? The list-payouts API responds with currency_code and that is the value you should be reading from.

But when converting Can you elaborate more on this

Cheers!

zenmasterjobo avatar Jul 25 '23 18:07 zenmasterjobo

@zenmasterjobo I'll try to explain my problem in code.

$apiClient = new \Square\SquareClient([
    'customUrl' => 'https://connect.squareup.com',
    'environment' => 'production',
    'accessToken' => $accessToken,
]);

$response = $apiClient->getPayoutsApi()->getPayout($payoutId);
assert($response instanceof \Square\Http\ApiResponse);

$result = $response->getResult();
assert($result instanceof \Square\Models\ListPayoutsResponse);

$payouts = $result->getPayoutEntries();

As a result, the $payouts variable contains an array of objects of the Square\Models\Payout class. In further logic I can't get the currency because it is not filled in the object.

When I add a method to the Square\Models\Money class, the property is filled in

public function setCurrencyCode(?string $currency): void
{
    $this->currency = $currency;
}

I think the main problem is that in the rest of the API the amount_money object is represented by the amount and currency properties (https://developer.squareup.com/reference/square/payments-api/get-payment). But in this API (https://developer.squareup.com/reference/square/payouts-api/list-payouts) uses amount and currency_code, so jsonMapper does not fill the object correctly

StApostol avatar Jul 26 '23 01:07 StApostol

Ahhh, yes - I understand your issue now, thanks for writing this up!

So this is actually bug with the payouts api endpoint, that we are still working on fixing.

In the meantime the workarounds that you can use here.

  1. You can $result = $response->getBody() which will give you the raw JSON response. You can then parse that and grab currency_code from there.

  2. For a given Square account, the currency will always be the same. So if you are just working with this one Square Account that is in AUD you can just use that assumption

Sorry for the unfavorable workarounds right now. The Payouts API team is actively working on how to best mitigate this bug.

Let me know if you need clarification or have further questions!

zenmasterjobo avatar Jul 26 '23 17:07 zenmasterjobo

@zenmasterjobo Thanks, hopefully the API will be fixed. Can you suggest how to get a list of payments and orders for payout more efficiently? My current method

  • get payout entries
  • extract payment and refund ids
  • for each id get information from payment or refund API
  • extract order ids
  • get orders information via batch order API

StApostol avatar Jul 28 '23 07:07 StApostol

@StApostol

Yeah, I'll try to remember to update this thread when that fix goes through!

And I think what you have there makes sense. I tried to think of some other spots you could shortcut on, but I don't think you can.

zenmasterjobo avatar Jul 28 '23 15:07 zenmasterjobo