Skip to content

Commit

Permalink
Release 1.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrowanwallee committed Jul 24, 2024
1 parent fc89b72 commit 7da9a2f
Show file tree
Hide file tree
Showing 23 changed files with 122 additions and 70 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# PrestaShop 8 WeArePlanet Integration
This repository contains the PrestaShop WeArePlanet payment module that enables the shop to process payments with [WeArePlanet](https://www.weareplanet.com/).

## To install module manually by dragging up zip file, please download [.zip archive](https://plugin-documentation.weareplanet.com/weareplanet/prestashop-8/1.0.7/weareplanet.zip) of module with correct structure required by Prestashop installation
## To install module manually by dragging up zip file, please download [.zip archive](https://plugin-documentation.weareplanet.com/weareplanet/prestashop-8/1.0.8/weareplanet.zip) of module with correct structure required by Prestashop installation

##### To use this extension, a [WeArePlanet](https://www.weareplanet.com/contact/sales) account is required.

Expand All @@ -12,15 +12,15 @@ This repository contains the PrestaShop WeArePlanet payment module that enables

## Documentation

* [English](https://plugin-documentation.weareplanet.com/weareplanet/prestashop-8/1.0.7/docs/en/documentation.html)
* [English](https://plugin-documentation.weareplanet.com/weareplanet/prestashop-8/1.0.8/docs/en/documentation.html)

## Support

Support queries can be issued on the [WeArePlanet support site](https://paymentshub.weareplanet.com/space/select?target=/support).

## License

Please see the [license file](https://github.com/weareplanet/prestashop-8/blob/1.0.7/LICENSE) for more information.
Please see the [license file](https://github.com/weareplanet/prestashop-8/blob/1.0.8/LICENSE) for more information.

## Other PrestaShop Versions

Expand Down
4 changes: 2 additions & 2 deletions docs/en/documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h2>Documentation</h2> </div>
</a>
</li>
<li>
<a href="https://github.com/weareplanet/prestashop-8/releases/tag/1.0.7/">
<a href="https://github.com/weareplanet/prestashop-8/releases/tag/1.0.8/">
Source
</a>
</li>
Expand All @@ -50,7 +50,7 @@ <h1>
<div class="olist arabic">
<ol class="arabic">
<li>
<p><a href="https://github.com/weareplanet/prestashop-8/releases/tag/1.0.7/">Download</a> the module.</p>
<p><a href="https://github.com/weareplanet/prestashop-8/releases/tag/1.0.8/">Download</a> the module.</p>
</li>
<li>
<p>Login to the backend of your PrestsShop store.</p>
Expand Down
2 changes: 1 addition & 1 deletion views/templates/admin/admin_help_buttons.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
<div class="alert alert-info">
<img src="../modules/weareplanet/logo.png" style="float:left; margin-right:15px;" height="50">
<p><strong>{l s='This module requires an %s account.' sprintf='WeArePlanet' mod='weareplanet'}</strong></p>
<p><a class="btn btn-default" href="https://www.weareplanet.com/contact/sales" target="_blank">{l s='Sign Up' mod='weareplanet'}</a> <a class="btn btn-default" href="https://plugin-documentation.weareplanet.com/weareplanet/prestashop-8/1.0.7/docs/en/documentation.html" target="_blank">{l s='Documentation' mod='weareplanet'}</a></p>
<p><a class="btn btn-default" href="https://www.weareplanet.com/contact/sales" target="_blank">{l s='Sign Up' mod='weareplanet'}</a> <a class="btn btn-default" href="https://plugin-documentation.weareplanet.com/weareplanet/prestashop-8/1.0.8/docs/en/documentation.html" target="_blank">{l s='Documentation' mod='weareplanet'}</a></p>
</div>
2 changes: 1 addition & 1 deletion weareplanet-sdk/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "weareplanet/sdk",
"version": "4.2.0",
"version": "4.4.0",
"description": "WeArePlanet SDK for PHP",
"keywords": [
"weareplanet",
Expand Down
6 changes: 3 additions & 3 deletions weareplanet-sdk/lib/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ final class ApiClient {
*
* @var string
*/
private $basePath = 'https://paymentshub.weareplanet.com:443/api';
private $basePath = 'https://app-wallee.com:443/api';

/**
* An array of headers that are added to every request.
*
* @var array
*/
private $defaultHeaders = [
'x-meta-sdk-version' => "4.2.0",
'x-meta-sdk-version' => "4.4.0",
'x-meta-sdk-language' => 'php',
'x-meta-sdk-provider' => "WeArePlanet",
];
Expand All @@ -58,7 +58,7 @@ final class ApiClient {
*
* @var string
*/
private $userAgent = 'PHP-Client/4.2.0/php';
private $userAgent = 'PHP-Client/4.4.0/php';

/**
* The path to the certificate authority file.
Expand Down
6 changes: 3 additions & 3 deletions weareplanet-sdk/lib/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Configuration
*
* @var string
*/
protected $userAgent = 'WeArePlanet\Sdk/4.2.0/php';
protected $userAgent = 'WeArePlanet\Sdk/4.4.0/php';

/**
* Debug switch (default set to false)
Expand Down Expand Up @@ -388,8 +388,8 @@ public static function toDebugReport()
$report = 'PHP SDK (WeArePlanet\Sdk) Debug Report:' . PHP_EOL;
$report .= ' OS: ' . php_uname() . PHP_EOL;
$report .= ' PHP Version: ' . PHP_VERSION . PHP_EOL;
$report .= ' OpenAPI Spec Version: 4.2.0' . PHP_EOL;
$report .= ' SDK Package Version: 4.2.0' . PHP_EOL;
$report .= ' OpenAPI Spec Version: 4.4.0' . PHP_EOL;
$report .= ' SDK Package Version: 4.4.0' . PHP_EOL;
$report .= ' Temp Folder Path: ' . self::getDefaultConfiguration()->getTempFolderPath() . PHP_EOL;

return $report;
Expand Down
106 changes: 79 additions & 27 deletions weareplanet-sdk/lib/Http/CurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/


declare(strict_types=1);

namespace WeArePlanet\Sdk\Http;

use WeArePlanet\Sdk\Http\ConnectionException;
Expand All @@ -33,14 +35,35 @@
*/
final class CurlHttpClient implements IHttpClient {

public function isSupported() {
/**
* Checks if curl is installed in the system.
*
* @return bool
*/
public function isSupported(): bool {
return function_exists('curl_version');
}

public function send(ApiClient $apiClient, HttpRequest $request) {
/**
* Sends the request using curl.
*
* The function will try to use the CA certificates provided by the system, first.
* If an error is detected, a second attempt will be done but this time using the
* CA certificates provided by this SDK.
* If this second attempt is valid, the SDK's CA certificates wil be stored in a
* temporal file ensuring upcoming request will use them. But if the second attempt
* also fails, then it means that the SDK's CA certificates do not help either, and
* will not be used anymore.
*
* @param ApiClient $apiClient
* @param HttpRequest $request
* @return HttpResponse
* @throws ConnectionException
*/
public function send(ApiClient $apiClient, HttpRequest $request): HttpResponse {
$curl = curl_init();

$tempCAFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "WeArePlanet-ca-bundle.crt";
$tempCAFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "tmp-ca-bundle.crt";

// set timeout, if needed
if ($request->getTimeOut() !== 0) {
Expand All @@ -62,7 +85,7 @@ public function send(ApiClient $apiClient, HttpRequest $request) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
if (file_exists($tempCAFile)) {
// use the temporal CA Bundle if it was set, which indicates a previous error.
// Use the temporal CA Bundle if it was set, which indicates a previous error.
$apiClient->setCertificateAuthority($tempCAFile);
curl_setopt($curl, CURLOPT_CAINFO, $apiClient->getCertificateAuthority());
}
Expand Down Expand Up @@ -96,7 +119,7 @@ public function send(ApiClient $apiClient, HttpRequest $request) {
// debugging for curl
$debugFilePointer = fopen($apiClient->getDebugFile(), 'a');
if ($apiClient->isDebuggingEnabled()) {
error_log("[DEBUG] HTTP Request body ~BEGIN~".PHP_EOL.print_r($request->getBody(), true).PHP_EOL."~END~".PHP_EOL, 3, $apiClient->getDebugFile());
error_log("[DEBUG] HTTP Request body ~BEGIN~" . PHP_EOL . print_r($request->getBody(), true) . PHP_EOL . "~END~" . PHP_EOL, 3, $apiClient->getDebugFile());

curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_STDERR, $debugFilePointer);
Expand All @@ -108,48 +131,78 @@ public function send(ApiClient $apiClient, HttpRequest $request) {
curl_setopt($curl, CURLOPT_HEADER, 1);

// Make the request
$response = curl_exec($curl);
if ($response) {
$response = $this->handleResponse($apiClient, $request, $curl, $response, $request->getUrl());
} else {
// if there was an error, try again with the CA bundle provided by this SDK.
if (!file_exists($tempCAFile)) {
$caContent = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "ca-bundle.crt");
$curlResponse = curl_exec($curl);
if ($curlResponse === FALSE && !file_exists($tempCAFile)) {
$errNo = curl_errno($curl);
$errStr = curl_error($curl);
if ($errNo === CURLE_SSL_CERTPROBLEM || substr_count(strtolower($errStr), "ssl")) {
$pathToCABundle = __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "ca-bundle.crt";
$caContent = file_get_contents($pathToCABundle);
// Create the temporal CA file, so it can be reused later on if needed.
file_put_contents($tempCAFile, $caContent);

// Try again the request, this time with the CA bundle provided by this SDK.
$apiClient->setCertificateAuthority($tempCAFile);
curl_setopt($curl, CURLOPT_CAINFO, $apiClient->getCertificateAuthority());
$response = curl_exec($curl);
$response = $this->handleResponse($apiClient, $request, $curl, $response, $request->getUrl());
$curlResponse = curl_exec($curl);
if ($curlResponse === FALSE) {
// The request still failed, so the CA bundle did not help.
// Restore system CA, and an error will be triggered later on.
unlink($tempCAFile);
}
}
}

curl_close($curl);
fclose($debugFilePointer);
try {
$httpResponse = $this->handleResponse($apiClient, $request, $curl, $curlResponse, $request->getUrl());
}
catch (ConnectionException $e) {
throw $e;
}
finally {
curl_close($curl);
fclose($debugFilePointer);
}

return $response;
return $httpResponse;
}

/**
* Puts together the HTTP response.
*
* @param ApiClient $apiClient the API client instance
* @param HttpRequest $request the HTTP request
* @param resource $curl the cURL handler
* @param mixed $response the response the of HTTP request
* @param string $url the url of the HTTP request
* @param ApiClient $apiClient
* The API client instance
* @param HttpRequest $request
* The HTTP request
* @param resource \CurlHandle $curl
* The cURL handler
* @param string|bool $curlResponse
* The response the from the $request, via curl_exec
* @param string $url
* The url of the HTTP request
* @return HttpResponse
* @throws ConnectionException
*/
private function handleResponse(ApiClient $apiClient, HttpRequest $request, $curl, $response, $url) {
private function handleResponse(ApiClient $apiClient, HttpRequest $request, \CurlHandle $curl, string|bool $curlResponse, string $url): HttpResponse {
$httpHeaderSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$httpHeader = substr($response, 0, $httpHeaderSize);
$httpBody = substr($response, $httpHeaderSize);

// Handle the case where $curlResponse is false (indicating an error)
if ($curlResponse === FALSE) {
$errStr = curl_error($curl);

if (!empty($errStr)) {
throw new ConnectionException($url, $request->getLogToken(), $errStr);
} else {
throw new ConnectionException($url, $request->getLogToken(), 'API call failed for an unknown reason.');
}
}
$httpHeader = substr($curlResponse, 0, $httpHeaderSize);
$httpBody = substr($curlResponse, $httpHeaderSize);
$responseInfo = curl_getinfo($curl);

// debug HTTP response body
if ($apiClient->isDebuggingEnabled()) {
error_log("[DEBUG] HTTP Response body ~BEGIN~".PHP_EOL.print_r($httpBody, true).PHP_EOL."~END~".PHP_EOL, 3, $apiClient->getDebugFile());
error_log("[DEBUG] HTTP Response body ~BEGIN~" . PHP_EOL . print_r($httpBody, true) . PHP_EOL . "~END~".PHP_EOL, 3, $apiClient->getDebugFile());
}

if ($responseInfo['http_code'] === 0) {
Expand All @@ -165,5 +218,4 @@ private function handleResponse(ApiClient $apiClient, HttpRequest $request, $cur
return new HttpResponse($responseInfo['http_code'], $httpHeader, $httpBody);
}
}

}
2 changes: 1 addition & 1 deletion weareplanet-sdk/lib/Model/ChargeAttempt.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ public function getLabels()
/**
* Sets labels
*
* @param \WeArePlanet\Sdk\Model\Label[] $labels
* @param \WeArePlanet\Sdk\Model\Label[] $labels The labels providing additional information about the object.
*
* @return $this
*/
Expand Down
8 changes: 4 additions & 4 deletions weareplanet-sdk/lib/Model/DocumentTemplateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function getDescription()
/**
* Sets description
*
* @param map[string,string] $description
* @param map[string,string] $description The localized description of the document template type.
*
* @return $this
*/
Expand All @@ -266,7 +266,7 @@ public function getFeature()
/**
* Sets feature
*
* @param int $feature
* @param int $feature The feature that this document template type belongs to.
*
* @return $this
*/
Expand All @@ -291,7 +291,7 @@ public function getGroup()
/**
* Sets group
*
* @param \WeArePlanet\Sdk\Model\DocumentTemplateTypeGroup $group
* @param \WeArePlanet\Sdk\Model\DocumentTemplateTypeGroup $group The group that this document template type belongs to.
*
* @return $this
*/
Expand Down Expand Up @@ -341,7 +341,7 @@ public function getTitle()
/**
* Sets title
*
* @param map[string,string] $title
* @param map[string,string] $title The localized title of the document template type.
*
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion weareplanet-sdk/lib/Model/DocumentTemplateTypeGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public function getTitle()
/**
* Sets title
*
* @param map[string,string] $title
* @param map[string,string] $title The localized title of the group.
*
* @return $this
*/
Expand Down
6 changes: 3 additions & 3 deletions weareplanet-sdk/lib/Model/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function getContent()
/**
* Sets content
*
* @param object $content
* @param object $content The label's actual content.
*
* @return $this
*/
Expand All @@ -266,7 +266,7 @@ public function getContentAsString()
/**
* Sets content_as_string
*
* @param string $content_as_string
* @param string $content_as_string The label's content formatted as string.
*
* @return $this
*/
Expand All @@ -291,7 +291,7 @@ public function getDescriptor()
/**
* Sets descriptor
*
* @param \WeArePlanet\Sdk\Model\LabelDescriptor $descriptor
* @param \WeArePlanet\Sdk\Model\LabelDescriptor $descriptor The descriptor that describes what information the label provides.
*
* @return $this
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public function getConditions()
/**
* Sets conditions
*
* @param int[] $conditions Conditions allow you to define criteria that a transaction must fulfill in order for the connector configuration to be considered for processing the payment.
* @param int[] $conditions Conditions allow to define criteria that a transaction must fulfill in order for the connector configuration to be considered for processing the payment.
*
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion weareplanet-sdk/lib/Model/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ public function getLabels()
/**
* Sets labels
*
* @param \WeArePlanet\Sdk\Model\Label[] $labels
* @param \WeArePlanet\Sdk\Model\Label[] $labels The labels providing additional information about the object.
*
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion weareplanet-sdk/lib/Model/StaticValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function getFeatures()
/**
* Sets features
*
* @param int[] $features
* @param int[] $features The features that this static value belongs to.
*
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion weareplanet-sdk/lib/Model/TokenVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ public function getLabels()
/**
* Sets labels
*
* @param \WeArePlanet\Sdk\Model\Label[] $labels
* @param \WeArePlanet\Sdk\Model\Label[] $labels The labels providing additional information about the object.
*
* @return $this
*/
Expand Down
Loading

0 comments on commit 7da9a2f

Please sign in to comment.