Skip to content

Commit

Permalink
Release 3.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrowanwallee committed Jul 22, 2024
1 parent 6c9a68b commit 82d31ef
Show file tree
Hide file tree
Showing 21 changed files with 178 additions and 60 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This repository contains the WeArePlanet plugin that enables WooCommerce to proc

## Documentation

* [Documentation](https://plugin-documentation.weareplanet.com/weareplanet/woocommerce/3.0.8/docs/en/documentation.html)
* [Documentation](https://plugin-documentation.weareplanet.com/weareplanet/woocommerce/3.0.9/docs/en/documentation.html)

## Support

Expand All @@ -33,4 +33,4 @@ ____________________________________________________________________________

## License

Please see the [license file](https://github.com/weareplanet/woocommerce/blob/3.0.8/LICENSE) for more information.
Please see the [license file](https://github.com/weareplanet/woocommerce/blob/3.0.9/LICENSE) for more information.
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -783,3 +783,10 @@ Tested against:
- [Tested Against] Woocommerce 9.0.2
- [Tested Against] PHP SDK 4.2.0

= 3.0.9 - Jul 22 2024 =
- [Bugfix] If payment fails, go back to checkout page.
- [Tested Against] PHP 8.0
- [Tested Against] Wordpress 6.6
- [Tested Against] Woocommerce 9.1.2
- [Tested Against] PHP SDK 4.4.0

2 changes: 1 addition & 1 deletion 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/woocommerce/releases/tag/3.0.8/">
<a href="https://github.com/weareplanet/woocommerce/releases/tag/3.0.9/">
Source
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function get_settings() {
$settings = array(
array(
'links' => array(
'https://plugin-documentation.weareplanet.com/weareplanet/woocommerce/3.0.8/docs/en/documentation.html' => __( 'Documentation', 'woo-weareplanet' ),
'https://plugin-documentation.weareplanet.com/weareplanet/woocommerce/3.0.9/docs/en/documentation.html' => __( 'Documentation', 'woo-weareplanet' ),
'https://www.weareplanet.com/contact/sales' => __( 'Sign Up', 'woo-weareplanet' ),
),
'type' => 'weareplanet_links',
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-weareplanet-migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public static function check_version() {
public static function plugin_row_meta( $links, $file ) {
if ( WC_WEAREPLANET_PLUGIN_BASENAME === $file ) {
$row_meta = array(
'docs' => '<a href="https://plugin-documentation.weareplanet.com/weareplanet/woocommerce/3.0.8/docs/en/documentation.html" aria-label="' . esc_attr__( 'View Documentation', 'woo-weareplanet' ) . '">' . esc_html__( 'Documentation', 'woo-weareplanet' ) . '</a>',
'docs' => '<a href="https://plugin-documentation.weareplanet.com/weareplanet/woocommerce/3.0.9/docs/en/documentation.html" aria-label="' . esc_attr__( 'View Documentation', 'woo-weareplanet' ) . '">' . esc_html__( 'Documentation', 'woo-weareplanet' ) . '</a>',
);

return array_merge( $links, $row_meta );
Expand Down
16 changes: 9 additions & 7 deletions includes/class-wc-weareplanet-return-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ protected static function process_failure( WC_Order $order ) {
if ( ! empty( $user_message ) ) {
WC()->session->set( 'weareplanet_failure_message', $user_message );
}
if ( $order->get_meta( '_weareplanet_pay_for_order', true, 'edit' ) ) {
$url = apply_filters( 'wc_weareplanet_pay_failure_url', $order->get_checkout_payment_url( false ), $order );
wp_redirect( $url );
} else {
$url = apply_filters( 'wc_weareplanet_checkout_failure_url', wc_get_checkout_url(), $order );
wp_redirect( $url );
}

// The order-pay functionality does not work currently with our plugin, so we don't
// redirect the user there.
// Otherwise we would get the url using:
// apply_filters( 'wc_weareplanet_pay_failure_url', $order->get_checkout_payment_url( false ), $order )

$url = apply_filters( 'wc_weareplanet_checkout_failure_url', wc_get_checkout_url(), $order );
wp_redirect( $url );

exit();
}
}
Expand Down
13 changes: 7 additions & 6 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: Planet Merchant Services Ltd
Tags: woocommerce WeArePlanet, woocommerce, WeArePlanet, payment, e-commerce, webshop, psp, invoice, packing slips, pdf, customer invoice, processing
Requires at least: 4.7
Tested up to: 6.5
Stable tag: 3.0.8
Stable tag: 3.0.9
License: Apache 2
License URI: http://www.apache.org/licenses/LICENSE-2.0

Expand All @@ -23,7 +23,7 @@ To use this extension, a WeArePlanet account is required. Sign up on [WeArePlane

== Documentation ==

Additional documentation for this plugin is available [here](https://plugin-documentation.weareplanet.com/weareplanet/woocommerce/3.0.8/docs/en/documentation.html).
Additional documentation for this plugin is available [here](https://plugin-documentation.weareplanet.com/weareplanet/woocommerce/3.0.9/docs/en/documentation.html).

== Support ==

Expand Down Expand Up @@ -58,8 +58,9 @@ Support queries can be issued on the [WeArePlanet support site](https://payments
== Changelog ==


= 3.0.8 - Jul 2 2024 =
= 3.0.9 - Jul 22 2024 =
- [Bugfix] If payment fails, go back to checkout page.
- [Tested Against] PHP 8.0
- [Tested Against] Wordpress 6.6.rc1
- [Tested Against] Woocommerce 9.0.2
- [Tested Against] PHP SDK 4.2.0
- [Tested Against] Wordpress 6.6
- [Tested Against] Woocommerce 9.1.2
- [Tested Against] PHP SDK 4.4.0
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.2",
"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.2",
'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.2/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.2/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.2' . PHP_EOL;
$report .= ' SDK Package Version: 4.2.2' . 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
110 changes: 91 additions & 19 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,13 +35,36 @@
*/
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 . "tmp-ca-bundle.crt";

// set timeout, if needed
if ($request->getTimeOut() !== 0) {
curl_setopt($curl, CURLOPT_TIMEOUT, $request->getTimeOut());
Expand All @@ -59,6 +84,11 @@ public function send(ApiClient $apiClient, HttpRequest $request) {
} else {
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.
$apiClient->setCertificateAuthority($tempCAFile);
curl_setopt($curl, CURLOPT_CAINFO, $apiClient->getCertificateAuthority());
}
}

if ($request->getMethod() === HttpRequest::POST) {
Expand Down Expand Up @@ -89,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 @@ -101,35 +131,78 @@ public function send(ApiClient $apiClient, HttpRequest $request) {
curl_setopt($curl, CURLOPT_HEADER, 1);

// Make the request
$response = curl_exec($curl);

$response = $this->handleResponse($apiClient, $request, $curl, $response, $request->getUrl());
$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());
$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 @@ -145,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
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/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 82d31ef

Please sign in to comment.