• Namespace
  • Class

Namespaces

  • Klarna
    • Exceptions
    • Rest
      • Checkout
      • CustomerToken
      • HostedPaymentPage
      • MerchantCardService
      • OrderManagement
      • Payments
      • Settlements
      • Transport
        • Exception

Interfaces

  • Klarna\Rest\Transport\Exception\ConnectorException
  1 <?php
  2 /**
  3  * Copyright 2014 Klarna AB
  4  *
  5  * Licensed under the Apache License, Version 2.0 (the "License");
  6  * you may not use this file except in compliance with the License.
  7  * You may obtain a copy of the License at
  8  *
  9  * http://www.apache.org/licenses/LICENSE-2.0
 10  *
 11  * Unless required by applicable law or agreed to in writing, software
 12  * distributed under the License is distributed on an "AS IS" BASIS,
 13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  * See the License for the specific language governing permissions and
 15  * limitations under the License.
 16  *
 17  * File containing the Payouts class.
 18  */
 19 
 20 namespace Klarna\Rest\Settlements;
 21 
 22 use GuzzleHttp\Exception\RequestException;
 23 use Klarna\Exceptions\NotApplicableException;
 24 use Klarna\Rest\Resource;
 25 use Klarna\Rest\Transport\Connector;
 26 use Klarna\Rest\Transport\Exception\ConnectorException;
 27 
 28 /**
 29  * Payouts resource.
 30  *
 31  * @example docs/examples/SettlementsAPI/Payouts/get_all_payouts.php Returns a collection of payouts
 32  * @example docs/examples/SettlementsAPI/Payouts/get_payout.php Returns a specific payout based on a payment reference
 33  * @example docs/examples/SettlementsAPI/Payouts/get_summary.php Returns a summary of payouts for each currency code
 34  */
 35 class Payouts extends Resource
 36 {
 37     /**
 38      * {@inheritDoc}
 39      */
 40     const ID_FIELD = 'payment_reference';
 41 
 42     /**
 43      * {@inheritDoc}
 44      */
 45     public static $path = '/settlements/v1/payouts';
 46 
 47     /**
 48      * Constructs Payouts instance.
 49      *
 50      * @param Connector $connector HTTP transport connector
 51      */
 52     public function __construct(Connector $connector)
 53     {
 54         parent::__construct($connector);
 55     }
 56 
 57     /**
 58      * Not applicable.
 59      *
 60      * @throws NotApplicableException
 61      */
 62     public function fetch()
 63     {
 64         throw new NotApplicableException('Not applicable');
 65     }
 66 
 67     /**
 68      * Returns a specific payout based on a given payment reference.
 69      *
 70      * @param string $paymentReference The reference id of the payout
 71      *
 72      * @throws ConnectorException        When the API replies with an error response
 73      * @throws RequestException          When an error is encountered
 74      * @throws \RuntimeException         On an unexpected API response
 75      * @throws \RuntimeException         If the response content type is not JSON
 76      * @throws \InvalidArgumentException If the JSON cannot be parsed
 77      * @throws \LogicException           When Guzzle cannot populate the response
 78      *
 79      * @return array Payout data
 80      */
 81     public function getPayout($paymentReference)
 82     {
 83         return $this->get(self::$path . "/{$paymentReference}")
 84             ->status('200')
 85             ->contentType('application/json')
 86             ->getJson();
 87     }
 88 
 89     /**
 90      * Returns a collection of payouts.
 91      *
 92      * @param array $params Additional query params to filter payouts.
 93      *
 94      * @see https://developers.klarna.com/api/#settlements-api-get-all-payouts
 95      *
 96      * @throws ConnectorException        When the API replies with an error response
 97      * @throws RequestException          When an error is encountered
 98      * @throws \RuntimeException         On an unexpected API response
 99      * @throws \RuntimeException         If the response content type is not JSON
100      * @throws \InvalidArgumentException If the JSON cannot be parsed
101      * @throws \LogicException           When Guzzle cannot populate the response
102      *
103      * @return array Payouts data
104      */
105     public function getAllPayouts(array $params = [])
106     {
107         return $this->get(self::$path . '?' . http_build_query($params))
108             ->status('200')
109             ->contentType('application/json')
110             ->getJson();
111     }
112 
113     /**
114      * Returns a summary of payouts for each currency code in a date range.
115      *
116      * @param array $params Additional query params to filter summary data.
117      *
118      * @see https://developers.klarna.com/api/#settlements-api-get-summary-of-payouts
119      *
120      * @throws ConnectorException        When the API replies with an error response
121      * @throws RequestException          When an error is encountered
122      * @throws \RuntimeException         On an unexpected API response
123      * @throws \RuntimeException         If the response content type is not JSON
124      * @throws \InvalidArgumentException If the JSON cannot be parsed
125      * @throws \LogicException           When Guzzle cannot populate the response
126      *
127      * @return array summary of payouts
128      */
129     public function getSummary(array $params = [])
130     {
131         return $this->get(self::$path . '/summary?' . http_build_query($params))
132             ->status('200')
133             ->contentType('application/json')
134             ->getJson();
135     }
136 }
137 
API documentation generated by ApiGen