Skip to content

Commit

Permalink
Release 4.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wallee-deployment-user committed Jul 16, 2024
1 parent 5c2c842 commit 1fed3c3
Show file tree
Hide file tree
Showing 56 changed files with 411 additions and 435 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wallee/sdk",
"version": "4.3.0",
"version": "4.4.0",
"description": "wallee SDK for PHP",
"keywords": [
"wallee",
Expand Down
4 changes: 2 additions & 2 deletions lib/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class ApiClient {
* @var array
*/
private $defaultHeaders = [
'x-meta-sdk-version' => "4.3.0",
'x-meta-sdk-version' => "4.4.0",
'x-meta-sdk-language' => 'php',
'x-meta-sdk-provider' => "wallee",
];
Expand All @@ -58,7 +58,7 @@ final class ApiClient {
*
* @var string
*/
private $userAgent = 'PHP-Client/4.3.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 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 = 'Wallee\Sdk/4.3.0/php';
protected $userAgent = 'Wallee\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 (Wallee\Sdk) Debug Report:' . PHP_EOL;
$report .= ' OS: ' . php_uname() . PHP_EOL;
$report .= ' PHP Version: ' . PHP_VERSION . PHP_EOL;
$report .= ' OpenAPI Spec Version: 4.3.0' . PHP_EOL;
$report .= ' SDK Package Version: 4.3.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
110 changes: 91 additions & 19 deletions 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 Wallee\Sdk\Http;

use Wallee\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);
}
}

}
16 changes: 8 additions & 8 deletions lib/Model/AbstractSubscriberUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function getAdditionalAllowedPaymentMethodConfigurations()
/**
* Sets additional_allowed_payment_method_configurations
*
* @param int[] $additional_allowed_payment_method_configurations Those payment methods which are allowed additionally will be available even when the product does not allow those methods.
* @param int[] $additional_allowed_payment_method_configurations Allow the subscriber to use these payment methods even if subscription products do not accept them.
*
* @return $this
*/
Expand All @@ -305,7 +305,7 @@ public function getBillingAddress()
/**
* Sets billing_address
*
* @param \Wallee\Sdk\Model\AddressCreate $billing_address
* @param \Wallee\Sdk\Model\AddressCreate $billing_address The address associated with the subscriber for invoicing and transaction processing purposes.
*
* @return $this
*/
Expand All @@ -330,7 +330,7 @@ public function getDescription()
/**
* Sets description
*
* @param string $description The subscriber description can be used to add a description to the subscriber. This is used in the back office to identify the subscriber.
* @param string $description The description used to identify the subscriber.
*
* @return $this
*/
Expand Down Expand Up @@ -359,7 +359,7 @@ public function getDisallowedPaymentMethodConfigurations()
/**
* Sets disallowed_payment_method_configurations
*
* @param int[] $disallowed_payment_method_configurations Those payment methods which are disallowed will not be available to the subscriber even if the product allows those methods.
* @param int[] $disallowed_payment_method_configurations Prevent the subscriber from using these payment methods even if subscription products do accept them.
*
* @return $this
*/
Expand All @@ -384,7 +384,7 @@ public function getEmailAddress()
/**
* Sets email_address
*
* @param string $email_address The email address is used to communicate with the subscriber. There can be only one subscriber per space with the same email address.
* @param string $email_address The email address that is used to communicate with the subscriber. There can be only one subscriber per space with the same email address.
*
* @return $this
*/
Expand Down Expand Up @@ -413,7 +413,7 @@ public function getLanguage()
/**
* Sets language
*
* @param string $language The subscriber language determines the language which is used to communicate with the subscriber in emails and documents (e.g. invoices).
* @param string $language The language that is used when communicating with the subscriber via emails and documents.
*
* @return $this
*/
Expand Down Expand Up @@ -463,7 +463,7 @@ public function getReference()
/**
* Sets reference
*
* @param string $reference The subscriber reference identifies the subscriber in administrative interfaces (e.g. customer id).
* @param string $reference The merchant's reference used to identify the subscriber.
*
* @return $this
*/
Expand Down Expand Up @@ -492,7 +492,7 @@ public function getShippingAddress()
/**
* Sets shipping_address
*
* @param \Wallee\Sdk\Model\AddressCreate $shipping_address
* @param \Wallee\Sdk\Model\AddressCreate $shipping_address The address to where orders will be shipped.
*
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Model/AbstractSubscriptionAffiliateUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public function getName()
/**
* Sets name
*
* @param string $name
* @param string $name The name used to identify the affiliate.
*
* @return $this
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/Model/AbstractSubscriptionMetricUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function getDescription()
/**
* Sets description
*
* @param map[string,string] $description
* @param map[string,string] $description The localized description of the metric that is displayed to the customer.
*
* @return $this
*/
Expand All @@ -244,7 +244,7 @@ public function getName()
/**
* Sets name
*
* @param map[string,string] $name
* @param map[string,string] $name The localized name of the metric that is displayed to the customer.
*
* @return $this
*/
Expand Down
10 changes: 5 additions & 5 deletions lib/Model/AbstractSubscriptionProductActive.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function getAllowedPaymentMethodConfigurations()
/**
* Sets allowed_payment_method_configurations
*
* @param int[] $allowed_payment_method_configurations The allowed payment method configurations control which payment methods can be used with this product. When none is selected all methods will be allowed.
* @param int[] $allowed_payment_method_configurations The payment methods that can be used to subscribe to this product. If none are selected, no restriction is applied.
*
* @return $this
*/
Expand All @@ -276,7 +276,7 @@ public function getFailedPaymentSuspensionPeriod()
/**
* Sets failed_payment_suspension_period
*
* @param string $failed_payment_suspension_period When a payment fails, the subscription to which the payment belongs to will be suspended. When the suspension is not removed within the specified period the subscription will be terminated. A payment is considered as failed when the subscriber issues a refund or when a subscription charge fails.
* @param string $failed_payment_suspension_period The period after which a subscription that has been suspended due to a failed payment is terminated.
*
* @return $this
*/
Expand All @@ -301,7 +301,7 @@ public function getName()
/**
* Sets name
*
* @param string $name The product name is used internally to identify the configuration in administrative interfaces. For example it is used within search fields and hence it should be distinct and descriptive.
* @param string $name The name used to identify the product.
*
* @return $this
*/
Expand Down Expand Up @@ -330,7 +330,7 @@ public function getProductLocked()
/**
* Sets product_locked
*
* @param bool $product_locked Marks the product as locked. Meaning that customer can not change away from this product or change to this product later on.
* @param bool $product_locked Whether subscriptions can be switched to or from this product, or whether they are locked in.
*
* @return $this
*/
Expand All @@ -355,7 +355,7 @@ public function getSortOrder()
/**
* Sets sort_order
*
* @param int $sort_order The sort order controls in which order the product is listed. The sort order is used to order the products in ascending order.
* @param int $sort_order When listing products, they can be sorted by this number.
*
* @return $this
*/
Expand Down
Loading

0 comments on commit 1fed3c3

Please sign in to comment.