bunq / sdk_php

PHP SDK for bunq API
MIT License
84 stars 54 forks source link

Allow access to `merchant_category_code` in the `counterparty_alias` #171

Closed timvdalen closed 5 years ago

timvdalen commented 5 years ago

Steps to reproduce:

  1. Get a reference to a Payment made with a card at a merchant POS
  2. Try to call $payment->getCounterpartyAlias()->getMerchantCategoryCode()

What should happen:

  1. Get the merchant's category code

What happens:

  1. getMerchantCategoryCode() is not defined on LabelMonetaryAccount (rightly so, as it is a more generic model than a specific merchant alias)

SDK version and environment

Extra info:

Alternatively, getting access to the raw JSON through a BunqResponse would be a good compromise if there is no way to fit this into the existing models. That way, users can extract extra fields they need themselves.

basst85 commented 5 years ago

@timvdalen Good wish 👍🏻

This field (merchant_category_code) is also not in the documentation (https://doc.bunq.com/#/payment/Read_Payment_for_User_MonetaryAccount), that is probably the cause @kojoru ?

timvdalen commented 5 years ago

Indeed, I found it through raw requests to the API

timvdalen commented 5 years ago

Any update on this?

OGKevin commented 5 years ago

🤷‍♂️, you could always edit the generated code manually and use that until this is fixed.

OGKevin commented 5 years ago

If you can provide a raw response example i could show you where/how to change the generated code.

timvdalen commented 5 years ago

Sure!

Considering this raw payment (with a bunch of fields omitted):

{"Payment":{
    ...,
    "counterparty_alias":{
       "iban":null,
       "is_light":null,
       "display_name":"AH",
       "avatar":{},
       "label_user":{
          "uuid":null,
          "display_name":"AH",
          "country":"NL",
          "avatar":null,
          "public_nick_name":"AH"
       },
       "country":"NL",
       "merchant_category_code":"5499"
    },
    ...
}}

I'm trying to get the merchant_category_code value.

OGKevin commented 5 years ago

Add the following


    /**
     * Why does it take so long to fix this.....
     *
     * @var string
     */
    protected $merchantCategoryCode;

    /**
     * @return string
     */
    public function getMerchantCategoryCode(): string
    {
        return $this->merchantCategoryCode;
    }

in src/Model/Generated/Object/LabelMonetaryAccount.php

and it should magically work fine.

timvdalen commented 5 years ago

Works great, thanks! One minor tweak to anyone else wanting to use this in the meantime, the category code is optional (as it only works for card payments) so remove the : string return type.

OGKevin commented 5 years ago

Np. I told them to let me maintain my maintainer status even thought i dont work there anymore (as an outside contributer/maintainer) but 🤷‍♂️. This takes 5 mins to fix in the generator :(.