Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #103 from heidelpay/change/PHPLIB-203/extend-paypa…
Browse files Browse the repository at this point in the history
…ge-tests

change/PHPLIB-203/extend-paypage-tests
  • Loading branch information
Simon Gabriel authored Aug 9, 2019
2 parents 46e1e99 + 5b7d17f commit 8b242dc
Show file tree
Hide file tree
Showing 8 changed files with 386 additions and 65 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
* Version and Type of the SDK are now sent to the API with every request.
* Add missing feature to readme.
* Renamed property `Basket::amountTotal` to `Basket::amountTotalGross` to follow the change in the API.
* Refactor tests.
* Set `Paypage` default action to 'charge' and restrict values to 'charge' and 'authorize'.

### Added
* Property `type` to `BasketItem`.
* Property `type` to `BasketItem`.
* An exception is now thrown in case of a `CURL` timeout.
* The `CURL` timeout can now be changed via environment variable.

### Removed
* Unnecessary resource setters in `Paypage`.

### Fixed
* Unit tests work now even in `development` or `staging` environment.

## [1.1.6.0][1.1.6.0]

Expand Down
4 changes: 0 additions & 4 deletions examples/InvoiceGuaranteed/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@
use heidelpayPHP\Exceptions\HeidelpayApiException;
use heidelpayPHP\Heidelpay;
use heidelpayPHP\Resources\Basket;
use heidelpayPHP\Resources\Customer;
use heidelpayPHP\Resources\EmbeddedResources\Address;
use heidelpayPHP\Resources\EmbeddedResources\BasketItem;
use heidelpayPHP\Resources\PaymentTypes\InvoiceFactoring;
use heidelpayPHP\Resources\PaymentTypes\InvoiceGuaranteed;

session_start();
session_unset();
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/CurlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function execute()
$errorMessage = 'Timeout: The Payment API seems to be not available at the moment!';
break;
default:
$errorMessage = 'An error occurred sending the request.';
$errorMessage = 'An error occurred sending the request (curl_errno: '. $error . ').';
break;
}
throw new HeidelpayApiException($errorMessage);
Expand Down
55 changes: 0 additions & 55 deletions src/Resources/PaymentTypes/Paypage.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,23 +407,6 @@ public function getBasket()
return $this->payment->getBasket();
}

/**
* @param Basket $basket
*
* @return Paypage
*
* @throws HeidelpayApiException
* @throws RuntimeException
*/
protected function setBasket(Basket $basket): Paypage
{
if (!$this->payment instanceof Payment) {
throw new RuntimeException('The payment resource is missing.');
}
$this->payment->setBasket($basket);
return $this;
}

/**
* @return Customer|null
*/
Expand All @@ -435,23 +418,6 @@ public function getCustomer()
return $this->payment->getCustomer();
}

/**
* @param Customer|null $customer
*
* @return Paypage
*
* @throws RuntimeException
* @throws HeidelpayApiException
*/
protected function setCustomer($customer): Paypage
{
if (!$this->payment instanceof Payment) {
throw new RuntimeException('The payment resource is missing.');
}
$this->payment->setCustomer($customer);
return $this;
}

/**
* @return Metadata|null
*/
Expand All @@ -463,23 +429,6 @@ public function getMetadata()
return $this->payment->getMetadata();
}

/**
* @param Metadata|null $metadata
*
* @return Paypage
*
* @throws HeidelpayApiException
* @throws RuntimeException
*/
protected function setMetadata($metadata): Paypage
{
if (!$this->payment instanceof Payment) {
throw new RuntimeException('The payment resource is missing.');
}
$this->payment->setMetadata($metadata);
return $this;
}

/**
* @return string|null
*/
Expand Down Expand Up @@ -567,10 +516,6 @@ public function handleResponse(stdClass $response, $method = HttpAdapterInterfac
$payment->setId($response->resources->paymentId);
}

if (isset($response->redirectUrl)) {
$payment->setRedirectUrl($response->redirectUrl);
}

if ($method !== HttpAdapterInterface::REQUEST_GET) {
$this->fetchPayment();
}
Expand Down
12 changes: 10 additions & 2 deletions test/unit/HeidelpayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
*/
namespace heidelpayPHP\test\unit;

use heidelpayPHP\Constants\TransactionTypes;
use heidelpayPHP\Heidelpay;
use heidelpayPHP\Resources\Basket;
use heidelpayPHP\Resources\Customer;
use heidelpayPHP\Resources\Metadata;
use heidelpayPHP\Resources\Payment;
use heidelpayPHP\Resources\PaymentTypes\Card;
use heidelpayPHP\Resources\PaymentTypes\Paypage;
use heidelpayPHP\Resources\PaymentTypes\Sofort;
use heidelpayPHP\Resources\TransactionTypes\Authorization;
use heidelpayPHP\Resources\TransactionTypes\Cancellation;
Expand Down Expand Up @@ -291,7 +293,8 @@ public function heidelpayShouldForwardResourceActionCallsToTheResourceServiceDP(
'fetchRefund' => ['fetchRefund', [$chargeMock, $cancelId], 'fetch', [$cancellation]],
'fetchShipment' => ['fetchShipment', [$payment, 'shipId'], 'fetchShipment', [$payment, 'shipId']],
'activateRecurring' => ['activateRecurringPayment', [$card, 'returnUrl'], 'createRecurring', [$card, 'returnUrl']],
'activateRecurringWithId' => ['activateRecurringPayment', [$paymentTypeId, 'returnUrl'], 'createRecurring', [$paymentTypeId, 'returnUrl']]
'activateRecurringWithId' => ['activateRecurringPayment', [$paymentTypeId, 'returnUrl'], 'createRecurring', [$paymentTypeId, 'returnUrl']],
'fetchPayout' => ['fetchPayout', [$payment], 'fetchPayout', [$payment]]
];
}

Expand All @@ -314,6 +317,8 @@ public function heidelpayShouldForwardPaymentActionCallsToThePaymentServiceDP():
$payment = new Payment();
$authorization = new Authorization();
$charge = new Charge();
$paypage = new Paypage(123.1234, 'EUR', 'url');
$basket = new Basket();

return [
'auth' => ['authorize', [1.234, 'AFN', $sofort, $url, $customer, $orderId, $metadata], 'authorize', [1.234, 'AFN', $sofort, $url, $customer, $orderId, $metadata]],
Expand All @@ -338,7 +343,10 @@ public function heidelpayShouldForwardPaymentActionCallsToThePaymentServiceDP():
'cancelChargeByIdAlt' => ['cancelChargeById', [$paymentId, $chargeId], 'cancelChargeById', [$paymentId, $chargeId]],
'cancelCharge' => ['cancelCharge', [$charge, 1.234], 'cancelCharge', [$charge, 1.234]],
'cancelChargeAlt' => ['cancelCharge', [$charge], 'cancelCharge', [$charge]],
'ship' => ['ship', [$payment], 'ship', [$payment]]
'ship' => ['ship', [$payment], 'ship', [$payment]],
'payout' => ['payout', [123, 'EUR', $paymentTypeId, 'url', $customer, $orderId, $metadata, 'basketId'], 'payout', [123, 'EUR', $paymentTypeId, 'url', $customer, $orderId, $metadata, 'basketId']],
'initPayPageCharge' => ['initPayPageCharge', [$paypage, $customer, $basket, $metadata], 'initPayPage', [$paypage, TransactionTypes::CHARGE, $customer, $basket, $metadata]],
'initPayPageAuthorize' => ['initPayPageAuthorize', [$paypage, $customer, $basket, $metadata], 'initPayPage', [$paypage, TransactionTypes::AUTHORIZATION, $customer, $basket, $metadata]]
];
}

Expand Down
4 changes: 4 additions & 0 deletions test/unit/Resources/AbstractHeidelpayResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use heidelpayPHP\Constants\CompanyCommercialSectorItems;
use heidelpayPHP\Constants\CompanyRegistrationTypes;
use heidelpayPHP\Constants\Salutations;
use heidelpayPHP\Constants\TransactionTypes;
use heidelpayPHP\Heidelpay;
use heidelpayPHP\Resources\AbstractHeidelpayResource;
use heidelpayPHP\Resources\Basket;
Expand All @@ -44,6 +45,7 @@
use heidelpayPHP\Resources\PaymentTypes\EPS;
use heidelpayPHP\Resources\PaymentTypes\Invoice;
use heidelpayPHP\Resources\PaymentTypes\InvoiceGuaranteed;
use heidelpayPHP\Resources\PaymentTypes\Paypage;
use heidelpayPHP\Resources\PaymentTypes\SepaDirectDebit;
use heidelpayPHP\Resources\PaymentTypes\SepaDirectDebitGuaranteed;
use heidelpayPHP\Resources\Recurring;
Expand Down Expand Up @@ -400,6 +402,8 @@ public function uriDataProvider(): array
'Webhooks' => [new Webhook(), 'parent/resource/path/webhooks/'],
'Recurring' => [new Recurring('s-crd-123', ''), 'parent/resource/path/types/s-crd-123/recurring/'],
'Payout' => [new Payout(), 'parent/resource/path/payouts/'],
'PayPage charge' => [new Paypage(123.4567, 'EUR', 'url'), 'parent/resource/path/paypage/charge/'],
'PayPage authorize' => [(new Paypage(123.4567, 'EUR', 'url'))->setAction(TransactionTypes::AUTHORIZATION), 'parent/resource/path/paypage/authorize/']
];
}

Expand Down
Loading

0 comments on commit 8b242dc

Please sign in to comment.