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

Commit

Permalink
PHPLIB-313/change/examples_always_create_heidelpay_instance_to_show_s…
Browse files Browse the repository at this point in the history
…andbox_banner (#187)

* [change] (PHPLIB-326) Enable test output for failed tests even when verbose test logging is disabled.

* [change] (PHPLIB-326) Replace environment variable for test log output and set default to false (no output).

* [change] (PHPLIB-326) Replace environment variable for test log output and set default to false (no output).

* [change] (PHPLIB-326) Update CHANGELOG.md.

* [change] (PHPLIB-326) Fix style issues.

* [change] (PHPLIB-326) Add new line before and after log dump.

* [change] (PHPLIB-326) Fix version in deprecation notice.

* [change] (PHPLIB-333) Remove default key pair from examples.

* [change] (PHPLIB-333) Update version since the changes are quite intence.

* [change] (PHPLIB-333) small change,.

* [change] (PHPLIB-333) small change,.

* [change] (PHPLIB-333) Fix key validation.

* [change] (PHPLIB-333) Move general key-check to index.

* [change] (PHPLIB-334) Remove default keys from tests and refactor tests.

* [change] (PHPLIB-334) Tests: Extend unit test for fetching the keys from env vars.

* [change] (PHPLIB-334) Tests: Changed EnvironmentService call to static method.

* [change] (PHPLIB-334) Tests: Refactor tests due to removal of default keys.

* [change] (PHPLIB-334) Tests: Changed EnvironmentService call to static method.

* [change] (PHPLIB-334) Tests: Update recurring test to comply to latest api changes.

* [change] (PHPLIB-334) Update README.md

* [change] (PHPLIB-334) Update README.md

* [change] (PHPLIB-334) Update CHANGELOG.md

* [refactor] (PHPLIB-317) Adapt style and features to PHP version 7.1.

* Add return type hints.
* Fix some minor issues.
* Add missing exception annotations.
* Remove unnecessary comments from tests.

* [refactor] (PHPLIB-317) Update CHANGELOG.md and replace abandoned codacy/coverage package.

* [refactor] (PHPLIB-317) Update CHANGELOG.md and replace abandoned codacy/coverage package.

* [refactor] (PHPLIB-317) Update CHANGELOG.md and replace abandoned codacy/coverage package.

* [refactor] (PHPLIB-317) Refactor code.

* Replace deprecated methods.
* Add some noinspection rules.
* Fixed some minor issues.

* [refactor] (PHPLIB-317) Remove debug code.

* [refactor] (PHPLIB-334) Fix style issues.

* [change] (PHPLIB-313) Examples/PrePayment: Create heidelpay object to make sure the sandbox banner is visible.

* [change] (PHPLIB-313) Examples/PrePayment: Create heidelpay object to make sure the sandbox banner is visible.

* [change] (PHPLIB-313) Update due to codacy issues.

* [change] (PHPLIB-313) Tests: Fix unit tests.

* [change] (PHPLIB-313) Add missing throws annotations.

* [change] (PHPLIB-313) Add missing throws annotations.

Co-authored-by: sixer1182 <[email protected]>
  • Loading branch information
Simon Gabriel and sixer1182 committed Jul 24, 2020
1 parent 957eca4 commit 99b43bb
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
* Refactor tests due to disabled default keypair.
* Refactor all files to reflect PHP 7.1 standards.
* Replace `codacy/coverage` with `codacy/codacy-coverage-reporter`.
* Update examples to always show the sandbox banner when sandbox keys are used.

### Fix
* Change TravisCI config to use default linux distribution in VM to fix certificate errors during integration tests.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ For any issues or questions please get in touch with our support team.
[https://docs.heidelpay.com/](https://docs.heidelpay.com/)

### Email
[email protected]
<[email protected]>

### Phone
+49 (0)6221/6471-100
Expand Down
5 changes: 5 additions & 0 deletions examples/EmbeddedPayPage/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
require_once __DIR__ . '/Constants.php';

/** @noinspection PhpIncludeInspection */

/** Require the composer autoloader file */
require_once __DIR__ . '/../../../../autoload.php';
?>
Expand Down Expand Up @@ -76,6 +77,10 @@
</form>

<script>
// Create a heidelpay instance with your public key
// This is not actually needed for this example but we want the sandbox banner to show on the page.
let heidelpayInstance = new heidelpay('<?php echo HEIDELPAY_PHP_PAYMENT_API_PUBLIC_KEY; ?>');

let $errorHolder = $('#error-holder');
let $submitButton = $('#submit-button');
let $form = $('#payment-form');
Expand Down
7 changes: 7 additions & 0 deletions examples/HostedPayPage/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
require_once __DIR__ . '/Constants.php';

/** @noinspection PhpIncludeInspection */

/** Require the composer autoloader file */
require_once __DIR__ . '/../../../../autoload.php';
?>
Expand Down Expand Up @@ -72,5 +73,11 @@
<button class="heidelpayUI primary button fluid" id="submit-button" type="submit">Pay</button>
</form>

<script>
// Create a heidelpay instance with your public key
// This is not actually needed for this example but we want the sandbox banner to show on the page.
let heidelpayInstance = new heidelpay('<?php echo HEIDELPAY_PHP_PAYMENT_API_PUBLIC_KEY; ?>');
</script

</body>
</html>
9 changes: 7 additions & 2 deletions examples/Invoice/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@
<title>
Heidelpay UI Examples
</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>

<link rel="stylesheet" href="https://static.heidelpay.com/v1/heidelpay.css" />
<script type="text/javascript" src="https://static.heidelpay.com/v1/heidelpay.js"></script>
</head>

<body style="margin: 70px 70px 0;">
Expand All @@ -51,5 +50,11 @@
<button class="heidelpayUI primary button fluid" id="submit-button" type="submit">Pay</button>
</form>

<script>
// Create a heidelpay instance with your public key
// This is not actually needed for this example but we want the sandbox banner to show on the page.
let heidelpayInstance = new heidelpay('<?php echo HEIDELPAY_PHP_PAYMENT_API_PUBLIC_KEY; ?>');
</script

</body>
</html>
8 changes: 6 additions & 2 deletions examples/InvoiceFactoring/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
<title>
Heidelpay UI Examples
</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>

<link rel="stylesheet" href="https://static.heidelpay.com/v1/heidelpay.css" />
<script type="text/javascript" src="https://static.heidelpay.com/v1/heidelpay.js"></script>
Expand All @@ -52,5 +50,11 @@
<button class="heidelpayUI primary button fluid" id="submit-button" type="submit">Pay</button>
</form>

<script>
// Create a heidelpay instance with your public key
// This is not actually needed for this example but we want the sandbox banner to show on the page.
let heidelpayInstance = new heidelpay('<?php echo HEIDELPAY_PHP_PAYMENT_API_PUBLIC_KEY; ?>');
</script

</body>
</html>
9 changes: 7 additions & 2 deletions examples/Prepayment/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@
<title>
Heidelpay UI Examples
</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>

<link rel="stylesheet" href="https://static.heidelpay.com/v1/heidelpay.css" />
<script type="text/javascript" src="https://static.heidelpay.com/v1/heidelpay.js"></script>
</head>

<body style="margin: 70px 70px 0;">
Expand All @@ -51,5 +50,11 @@
<button class="heidelpayUI primary button fluid" id="submit-button" type="submit">Pay</button>
</form>

<script>
// Create a heidelpay instance with your public key
// This is not actually needed for this example but we want the sandbox banner to show on the page.
let heidelpayInstance = new heidelpay('<?php echo HEIDELPAY_PHP_PAYMENT_API_PUBLIC_KEY; ?>');
</script

</body>
</html>
2 changes: 1 addition & 1 deletion src/Adapter/CurlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct()
public function init($url, $payload = null, $httpMethod = HttpAdapterInterface::REQUEST_GET): void
{
$timeout = EnvironmentService::getTimeout();
$curlVerbose = EnvironmentService::getCurlVerbose();
$curlVerbose = EnvironmentService::isCurlVerbose();

$this->request = curl_init($url);
$this->setOption(CURLOPT_HEADER, 0);
Expand Down
20 changes: 9 additions & 11 deletions src/Services/EnvironmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected static function getBoolEnvValue(string $varName): bool
/** @noinspection ProperNullCoalescingOperatorUsageInspection */
$envVar = $_SERVER[$varName] ?? false;
if (!is_bool($envVar)) {
$envVar = in_array(strtolower($envVar), [true, 'true', '1'], true);
$envVar = in_array(strtolower(stripslashes($envVar)), [true, 'true', '1'], true);
}
return $envVar;
}
Expand All @@ -72,7 +72,7 @@ protected static function getBoolEnvValue(string $varName): bool
*/
public function getMgwEnvironment(): string
{
return $_SERVER[self::ENV_VAR_NAME_ENVIRONMENT] ?? self::ENV_VAR_VALUE_PROD_ENVIRONMENT;
return stripslashes($_SERVER[self::ENV_VAR_NAME_ENVIRONMENT] ?? self::ENV_VAR_VALUE_PROD_ENVIRONMENT);
}

/**
Expand All @@ -83,11 +83,9 @@ public function getMgwEnvironment(): string
public static function isTestLoggingActive(): bool
{
if (isset($_SERVER[self::ENV_VAR_NAME_VERBOSE_TEST_LOGGING])) {
$verboseLogging = self::getBoolEnvValue(self::ENV_VAR_NAME_VERBOSE_TEST_LOGGING);
} else {
$verboseLogging = !self::getBoolEnvValue(self::ENV_VAR_NAME_DISABLE_TEST_LOGGING);
return self::getBoolEnvValue(self::ENV_VAR_NAME_VERBOSE_TEST_LOGGING);
}
return $verboseLogging;
return !self::getBoolEnvValue(self::ENV_VAR_NAME_DISABLE_TEST_LOGGING);
}

/**
Expand All @@ -98,7 +96,7 @@ public static function isTestLoggingActive(): bool
*/
public static function getTimeout(): int
{
$timeout = $_SERVER[self::ENV_VAR_NAME_TIMEOUT] ?? '';
$timeout = stripslashes($_SERVER[self::ENV_VAR_NAME_TIMEOUT] ?? '');
return is_numeric($timeout) ? (int)$timeout : self::DEFAULT_TIMEOUT;
}

Expand All @@ -107,9 +105,9 @@ public static function getTimeout(): int
*
* @return bool
*/
public static function getCurlVerbose(): bool
public static function isCurlVerbose(): bool
{
$curlVerbose = strtolower($_SERVER[self::ENV_VAR_NAME_CURL_VERBOSE] ?? 'false');
$curlVerbose = strtolower(stripslashes($_SERVER[self::ENV_VAR_NAME_CURL_VERBOSE] ?? 'false'));
return in_array($curlVerbose, ['true', '1'], true);
}

Expand All @@ -125,7 +123,7 @@ public static function getCurlVerbose(): bool
public static function getTestPrivateKey($non3ds = false): string
{
$variableName = $non3ds ? self::ENV_VAR_TEST_PRIVATE_KEY_NON_3DS : self::ENV_VAR_TEST_PRIVATE_KEY;
$key = $_SERVER[$variableName] ?? '';
$key = stripslashes($_SERVER[$variableName] ?? '');
return empty($key) ? '' : $key;
}

Expand All @@ -141,7 +139,7 @@ public static function getTestPrivateKey($non3ds = false): string
public static function getTestPublicKey($non3ds = false): string
{
$variableName = $non3ds ? self::ENV_VAR_TEST_PUBLIC_KEY_NON_3DS : self::ENV_VAR_TEST_PUBLIC_KEY;
$key = $_SERVER[$variableName] ?? '';
$key = stripslashes($_SERVER[$variableName] ?? '');
return empty($key) ? '' : $key;
}
}
1 change: 0 additions & 1 deletion src/Services/IdService.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public static function getLastResourceIdFromUrlString($url): ?string
*/
public static function getResourceTypeFromIdString($typeId): ?string
{
$paymentType = null;
$typeIdString = null;

$typeIdParts = [];
Expand Down
1 change: 1 addition & 0 deletions src/Services/ResourceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ public function deleteResource(AbstractHeidelpayResource &$resource): ?AbstractH
*
* @throws HeidelpayApiException A HeidelpayApiException is thrown if there is an error returned on API-request.
* @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK.
* @throws Exception
*/
public function fetchResource(AbstractHeidelpayResource $resource): AbstractHeidelpayResource
{
Expand Down

0 comments on commit 99b43bb

Please sign in to comment.