mollie / mollie-api-php

Mollie API client for PHP
http://www.mollie.com
BSD 2-Clause "Simplified" License
552 stars 191 forks source link

Add ?include=pricing to Methods API #335

Closed sandervanhooft closed 5 years ago

sandervanhooft commented 5 years ago

Specifications

Describe the issue

As suggested by @MollieRick in #332, we should include support for ?include=pricing option in the Methods API. I'll come up with a PR later.

sandervanhooft commented 5 years ago

Example response (includes issuers as well):

HTTP/1.1 200 OK
Content-Type: application/hal+json

{
     "resource": "method",
     "id": "ideal",
     "description": "iDEAL",
     "image": {
         "size1x": "https://www.mollie.com/external/icons/payment-methods/ideal.png",
         "size2x": "https://www.mollie.com/external/icons/payment-methods/ideal%402x.png",
         "svg": "https://www.mollie.com/external/icons/payment-methods/ideal.svg"
     },
     "issuers": [
         {
             "resource": "issuer",
             "id": "ideal_ABNANL2A",
             "name": "ABN AMRO",
             "image": {
                 "size1x": "https://www.mollie.com/external/icons/ideal-issuers/ABNANL2A.png",
                 "size2x": "https://www.mollie.com/external/icons/ideal-issuers/ABNANL2A%402x.png",
                 "svg": "https://www.mollie.com/external/icons/ideal-issuers/ABNANL2A.svg"
             }
         },
         {
             "resource": "issuer",
             "id": "ideal_ASNBNL21",
             "name": "ASN Bank",
             "image": {
                 "size1x": "https://www.mollie.com/external/icons/ideal-issuers/ASNBNL21.png",
                 "size2x": "https://www.mollie.com/external/icons/ideal-issuers/ASNBNL21%402x.png",
                 "svg": "https://www.mollie.com/external/icons/ideal-issuers/ASNBNL21.svg"
             }
         },
         { },
         { }
     ],
     "pricing": [
         {
             "description": "The Netherlands",
             "fixed": {
                 "value": "0.29",
                 "currency": "EUR"
             },
             "variable": "0"
         }
     ],
     "_links": {
         "self": {
             "href": "https://api.mollie.com/v2/methods/ideal",
             "type": "application/hal+json"
         },
         "documentation": {
             "href": "https://docs.mollie.com/reference/v2/methods-api/get-method",
             "type": "text/html"
         }
     }
 }
MollieRick commented 5 years ago

Small note: ?include=pricing will not include issuers by default.

sandervanhooft commented 5 years ago

Ok, so I noted that unlike issuer, pricing yields no dedicated resource in the API response. (Issuer has a issuer resource field, pricing does not.

So for now I have implemented pricing without a dedicated resource class.

sandervanhooft commented 5 years ago

So you access it using method->pricing[0].

sandervanhooft commented 5 years ago

Let me know if there should be a $method->pricing() method to access a MethodPricingCollection (or something more aptly named).

MollieRick commented 5 years ago

I think $method->pricing() is more in line with the other parts of the client. How I see it is that you can loop through the pricing, like:


foreach ($method->pricing() as $pricing) {
echo "Pricing for: " . $pricing->description;
echo "Fixed price: " . $pricing->fixed->value;
echo "Variable: " . $pricing->variable . "%";
}