AuthorizeNet / sample-code-php

This repository contains working code samples which demonstrate php integration with the Authorize.Net API
MIT License
175 stars 197 forks source link

get-list-of-subscriptions.php 小问题 #91

Closed phpstudyone closed 7 years ago

phpstudyone commented 7 years ago

RecurringBilling/get-list-of-subscriptions.php 文件中,使用了如下代码:

    $sorting = new AnetAPI\ARBGetSubscriptionListSortingType();
    $sorting->setOrderBy("id");
    $sorting->setOrderDescending("false");

但是实际上 setOrderDescending 接受的参数应该为 true 或者 false;

看意图是不进行倒序排列,但是如果传递"false"参数是为 true的,是倒序排列的,这会带来困惑。

adavidw commented 7 years ago

I have translated through Google Translate, so I hope that I understand correctly.

In this code, if the setOrderDescending parameter is set to "false", the order will be ascending by "id". If the setOrderDescending parameter is set to true, then the order will be descending by "id".

If you don't send either setOrderBy or setOrderDescending, the default behavior would be to return the results in ascending order by "id"

phpstudyone commented 7 years ago

"false" typeof is string .
false typeof is bool .

identify $sorting->setOrderDescending("false"); with $sorting->setOrderDescending(true);

we can use

$sorting->setOrderDescending(false);

rather than

$sorting->setOrderDescending("false");
adavidw commented 7 years ago

Ah, I think I understand.

If you put the value as "false", during the serialization process, it's turned to "true". That's because the serializer knows it should be boolean, and in PHP, any string that's not "0" is considered to be true: https://stackoverflow.com/questions/2382490/how-does-true-false-work-in-php

I committed a fix to the sample code to show the value as (false) instead of ("false"), which works correctly.

Thanks for the notification.