This repository has been archived by the owner on Jun 2, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from klarna/hpp_plus_card_service
Fix Hosted Payment Page API Add support of Merchant Card Service API
- Loading branch information
Showing
8 changed files
with
326 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
<?php | ||
/** | ||
* Copyright 2014 Klarna AB | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* File containing the Virtual Credit Card Settlements class. | ||
*/ | ||
|
||
namespace Klarna\Rest\MerchantCardService; | ||
|
||
use GuzzleHttp\Exception\RequestException; | ||
use Klarna\Rest\Resource; | ||
use Klarna\Rest\Transport\Connector; | ||
use Klarna\Rest\Transport\Exception\ConnectorException; | ||
use Klarna\Exceptions\NotApplicableException; | ||
|
||
/** | ||
* Virtual Credit Card Settlements resource. | ||
*/ | ||
class VCCSettlements extends Resource | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
const ID_FIELD = 'settlement_id'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static $path = '/merchantcard/v3/settlements'; | ||
|
||
/** | ||
* Constructs a session instance. | ||
* | ||
* @param Connector $connector HTTP transport connector | ||
* @param string $sessionId Session ID | ||
*/ | ||
public function __construct(Connector $connector) | ||
{ | ||
parent::__construct($connector); | ||
} | ||
|
||
/** | ||
* Not applicable. | ||
* | ||
* @throws NotApplicableException | ||
*/ | ||
public function fetch() | ||
{ | ||
throw new NotApplicableException('Not applicable'); | ||
} | ||
|
||
/** | ||
* Creates a new settlement. | ||
* | ||
* @param array $data Creation data | ||
* | ||
* @see https://developers.klarna.com/api/#merchant-card-service-api-create-a-new-settlement | ||
* | ||
* @throws ConnectorException When the API replies with an error response | ||
* @throws RequestException When an error is encountered | ||
* @throws \RuntimeException If the location header is missing | ||
* @throws \RuntimeException If the API replies with an unexpected response | ||
* @throws \LogicException When Guzzle cannot populate the response | ||
* | ||
* @return array Settlement data | ||
*/ | ||
public function create(array $data) | ||
{ | ||
$data = $this->post(self::$path, $data) | ||
->status('201') | ||
->contentType('application/json') | ||
->getJson(); | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* Retrieve an existing settlement. | ||
* | ||
* @see https://developers.klarna.com/api/#hosted-payment-page-api-distribute-link-to-the-hpp-session | ||
* | ||
* @param array $data Distribute data | ||
* | ||
* @throws ConnectorException When the API replies with an error response | ||
* @throws RequestException When an error is encountered | ||
* @throws \RuntimeException On an unexpected API response | ||
* @throws \RuntimeException If the response content type is not JSON | ||
* @throws \InvalidArgumentException If the JSON cannot be parsed | ||
* @throws \LogicException When Guzzle cannot populate the response | ||
* | ||
* @return array Settlement data | ||
*/ | ||
public function retrieveSettlement($settlementId, $keyId) | ||
{ | ||
$data = $this->request( | ||
'GET', | ||
self::$path . "/$settlementId", | ||
['KeyId' => $keyId] | ||
)->status('200') | ||
->contentType('application/json') | ||
->getJson(); | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* Retrieves a settled order's settlement. | ||
* | ||
* @see https://developers.klarna.com/api/#hosted-payment-page-api-distribute-link-to-the-hpp-session | ||
* | ||
* @param array $data Distribute data | ||
* | ||
* @throws ConnectorException When the API replies with an error response | ||
* @throws RequestException When an error is encountered | ||
* @throws \RuntimeException On an unexpected API response | ||
* @throws \RuntimeException If the response content type is not JSON | ||
* @throws \InvalidArgumentException If the JSON cannot be parsed | ||
* @throws \LogicException When Guzzle cannot populate the response | ||
* | ||
* @return array Order's settlement data | ||
*/ | ||
public function retrieveOrderSettlement($orderId, $keyId) | ||
{ | ||
$data = $this->request( | ||
'GET', | ||
self::$path . "/order/$orderId", | ||
['KeyId' => $keyId] | ||
)->status('200') | ||
->contentType('application/json') | ||
->getJson(); | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.