mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 10:55:00 +08:00
codestyle
This commit is contained in:
parent
6793d7217a
commit
9dc3c073d2
35 changed files with 205 additions and 144 deletions
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\AdminNotices;
|
namespace Inpsyde\PayPalCommerce\AdminNotices;
|
||||||
|
|
||||||
use Dhii\Modular\Module\ModuleInterface;
|
use Dhii\Modular\Module\ModuleInterface;
|
||||||
|
|
||||||
return function (): ModuleInterface {
|
return static function (): ModuleInterface {
|
||||||
return new AdminNotices();
|
return new AdminNotices();
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,13 +19,13 @@ use Inpsyde\PayPalCommerce\Button\Endpoint\RequestData;
|
||||||
use Inpsyde\PayPalCommerce\Button\Exception\RuntimeException;
|
use Inpsyde\PayPalCommerce\Button\Exception\RuntimeException;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'admin-notices.renderer' => function(ContainerInterface $container) : RendererInterface {
|
'admin-notices.renderer' => static function (ContainerInterface $container): RendererInterface {
|
||||||
|
|
||||||
$repository = $container->get('admin-notices.repository');
|
$repository = $container->get('admin-notices.repository');
|
||||||
return new Renderer($repository);
|
return new Renderer($repository);
|
||||||
},
|
},
|
||||||
'admin-notices.repository' => function(ContainerInterface $container) : RepositoryInterface {
|
'admin-notices.repository' => static function (ContainerInterface $container): RepositoryInterface {
|
||||||
|
|
||||||
return new Repository();
|
return new Repository();
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\AdminNotices\Entity;
|
namespace Inpsyde\PayPalCommerce\AdminNotices\Entity;
|
||||||
|
|
||||||
|
|
||||||
class Message
|
class Message
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -17,17 +17,17 @@ class Message
|
||||||
$this->dismissable = $dismissable;
|
$this->dismissable = $dismissable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function message() : string
|
public function message(): string
|
||||||
{
|
{
|
||||||
return $this->message;
|
return $this->message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function type() : string
|
public function type(): string
|
||||||
{
|
{
|
||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isDismissable() : bool
|
public function isDismissable(): bool
|
||||||
{
|
{
|
||||||
return $this->dismissable;
|
return $this->dismissable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\AdminNotices\Renderer;
|
namespace Inpsyde\PayPalCommerce\AdminNotices\Renderer;
|
||||||
|
|
||||||
|
|
||||||
interface RendererInterface
|
interface RendererInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
public function render() : bool;
|
public function render(): bool;
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\AdminNotices\Repository;
|
namespace Inpsyde\PayPalCommerce\AdminNotices\Repository;
|
||||||
|
@ -11,5 +12,5 @@ interface RepositoryInterface
|
||||||
/**
|
/**
|
||||||
* @return Message[]
|
* @return Message[]
|
||||||
*/
|
*/
|
||||||
public function currentMessages() : array;
|
public function currentMessages(): array;
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\Button;
|
namespace Inpsyde\PayPalCommerce\Button;
|
||||||
|
|
||||||
use Dhii\Modular\Module\ModuleInterface;
|
use Dhii\Modular\Module\ModuleInterface;
|
||||||
|
|
||||||
return function (): ModuleInterface {
|
return static function (): ModuleInterface {
|
||||||
return new ButtonModule();
|
return new ButtonModule();
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,7 +15,7 @@ use Inpsyde\PayPalCommerce\Button\Endpoint\RequestData;
|
||||||
use Inpsyde\PayPalCommerce\Button\Exception\RuntimeException;
|
use Inpsyde\PayPalCommerce\Button\Exception\RuntimeException;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'button.smart-button' => function (ContainerInterface $container): SmartButtonInterface {
|
'button.smart-button' => static function (ContainerInterface $container): SmartButtonInterface {
|
||||||
$settings = $container->get('wcgateway.settings');
|
$settings = $container->get('wcgateway.settings');
|
||||||
$payeeRepository = $container->get('api.repository.payee');
|
$payeeRepository = $container->get('api.repository.payee');
|
||||||
if (wc_string_to_bool($settings->get('enabled'))) {
|
if (wc_string_to_bool($settings->get('enabled'))) {
|
||||||
|
@ -28,16 +28,16 @@ return [
|
||||||
}
|
}
|
||||||
return new DisabledSmartButton();
|
return new DisabledSmartButton();
|
||||||
},
|
},
|
||||||
'button.url' => function (ContainerInterface $container): string {
|
'button.url' => static function (ContainerInterface $container): string {
|
||||||
return plugins_url(
|
return plugins_url(
|
||||||
'/modules/ppcp-button/',
|
'/modules/ppcp-button/',
|
||||||
dirname(__FILE__, 3) . '/woocommerce-paypal-commerce-gateway.php'
|
dirname(__FILE__, 3) . '/woocommerce-paypal-commerce-gateway.php'
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'button.request-data' => function (ContainerInterface $container): RequestData {
|
'button.request-data' => static function (ContainerInterface $container): RequestData {
|
||||||
return new RequestData();
|
return new RequestData();
|
||||||
},
|
},
|
||||||
'button.endpoint.change-cart' => function (ContainerInterface $container): ChangeCartEndpoint {
|
'button.endpoint.change-cart' => static function (ContainerInterface $container): ChangeCartEndpoint {
|
||||||
if (!\WC()->cart) {
|
if (!\WC()->cart) {
|
||||||
throw new RuntimeException('cant initialize endpoint at this moment');
|
throw new RuntimeException('cant initialize endpoint at this moment');
|
||||||
}
|
}
|
||||||
|
@ -47,14 +47,14 @@ return [
|
||||||
$repository = $container->get('api.repository.cart');
|
$repository = $container->get('api.repository.cart');
|
||||||
return new ChangeCartEndpoint($cart, $shipping, $requestData, $repository);
|
return new ChangeCartEndpoint($cart, $shipping, $requestData, $repository);
|
||||||
},
|
},
|
||||||
'button.endpoint.create-order' => function (ContainerInterface $container): CreateOrderEndpoint {
|
'button.endpoint.create-order' => static function (ContainerInterface $container): CreateOrderEndpoint {
|
||||||
$requestData = $container->get('button.request-data');
|
$requestData = $container->get('button.request-data');
|
||||||
$repository = $container->get('api.repository.cart');
|
$repository = $container->get('api.repository.cart');
|
||||||
$apiClient = $container->get('api.endpoint.order');
|
$apiClient = $container->get('api.endpoint.order');
|
||||||
$payerFactory = $container->get('api.factory.payer');
|
$payerFactory = $container->get('api.factory.payer');
|
||||||
return new CreateOrderEndpoint($requestData, $repository, $apiClient, $payerFactory);
|
return new CreateOrderEndpoint($requestData, $repository, $apiClient, $payerFactory);
|
||||||
},
|
},
|
||||||
'button.endpoint.approve-order' => function (ContainerInterface $container): ApproveOrderEndpoint {
|
'button.endpoint.approve-order' => static function (ContainerInterface $container): ApproveOrderEndpoint {
|
||||||
$requestData = $container->get('button.request-data');
|
$requestData = $container->get('button.request-data');
|
||||||
$apiClient = $container->get('api.endpoint.order');
|
$apiClient = $container->get('api.endpoint.order');
|
||||||
$sessionHandler = $container->get('session.handler');
|
$sessionHandler = $container->get('session.handler');
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\Button\Assets;
|
namespace Inpsyde\PayPalCommerce\Button\Assets;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\Button\Assets;
|
namespace Inpsyde\PayPalCommerce\Button\Assets;
|
||||||
|
@ -32,7 +33,7 @@ class SmartButton implements SmartButtonInterface
|
||||||
|
|
||||||
public function renderWrapper(): bool
|
public function renderWrapper(): bool
|
||||||
{
|
{
|
||||||
$renderer = function () {
|
$renderer = static function () {
|
||||||
echo '<div id="ppc-button"></div>';
|
echo '<div id="ppc-button"></div>';
|
||||||
};
|
};
|
||||||
if (is_cart() && wc_string_to_bool($this->settings->get('button_cart_enabled'))) {
|
if (is_cart() && wc_string_to_bool($this->settings->get('button_cart_enabled'))) {
|
||||||
|
@ -52,7 +53,7 @@ class SmartButton implements SmartButtonInterface
|
||||||
if (wc_string_to_bool($this->settings->get('button_mini_cart_enabled'))) {
|
if (wc_string_to_bool($this->settings->get('button_mini_cart_enabled'))) {
|
||||||
add_action(
|
add_action(
|
||||||
'woocommerce_widget_shopping_cart_after_buttons',
|
'woocommerce_widget_shopping_cart_after_buttons',
|
||||||
function () {
|
static function () {
|
||||||
echo '<p id="ppc-button-minicart" class="woocommerce-mini-cart__buttons buttons"></p>';
|
echo '<p id="ppc-button-minicart" class="woocommerce-mini-cart__buttons buttons"></p>';
|
||||||
},
|
},
|
||||||
30
|
30
|
||||||
|
@ -70,7 +71,10 @@ class SmartButton implements SmartButtonInterface
|
||||||
{
|
{
|
||||||
wp_enqueue_script(
|
wp_enqueue_script(
|
||||||
'paypal-smart-button',
|
'paypal-smart-button',
|
||||||
$this->moduleUrl . '/assets/js/button.js'
|
$this->moduleUrl . '/assets/js/button.js',
|
||||||
|
['jquery'],
|
||||||
|
1,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
wp_localize_script(
|
wp_localize_script(
|
||||||
|
@ -81,7 +85,7 @@ class SmartButton implements SmartButtonInterface
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function localizeScript() : array
|
private function localizeScript(): array
|
||||||
{
|
{
|
||||||
$localize = [
|
$localize = [
|
||||||
'redirect' => wc_get_checkout_url(),
|
'redirect' => wc_get_checkout_url(),
|
||||||
|
@ -117,7 +121,9 @@ class SmartButton implements SmartButtonInterface
|
||||||
return $localize;
|
return $localize;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function payerData() : ?array {
|
private function payerData(): ?array
|
||||||
|
{
|
||||||
|
|
||||||
$customer = WC()->customer;
|
$customer = WC()->customer;
|
||||||
if (! is_user_logged_in() || ! is_a($customer, \WC_Customer::class)) {
|
if (! is_user_logged_in() || ! is_a($customer, \WC_Customer::class)) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -145,7 +151,7 @@ class SmartButton implements SmartButtonInterface
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function url() : string
|
private function url(): string
|
||||||
{
|
{
|
||||||
$params = [
|
$params = [
|
||||||
//ToDo: Add the correct client id, toggle when settings is set to sandbox
|
//ToDo: Add the correct client id, toggle when settings is set to sandbox
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\Button\Assets;
|
namespace Inpsyde\PayPalCommerce\Button\Assets;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\Button;
|
namespace Inpsyde\PayPalCommerce\Button;
|
||||||
|
@ -19,8 +20,8 @@ class ButtonModule implements ModuleInterface
|
||||||
public function setup(): ServiceProviderInterface
|
public function setup(): ServiceProviderInterface
|
||||||
{
|
{
|
||||||
return new ServiceProvider(
|
return new ServiceProvider(
|
||||||
require __DIR__.'/../services.php',
|
require __DIR__ . '/../services.php',
|
||||||
require __DIR__.'/../extensions.php'
|
require __DIR__ . '/../extensions.php'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +35,7 @@ class ButtonModule implements ModuleInterface
|
||||||
*/
|
*/
|
||||||
add_action(
|
add_action(
|
||||||
'wp',
|
'wp',
|
||||||
function () use ($container) {
|
static function () use ($container) {
|
||||||
if (is_admin()) {
|
if (is_admin()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +43,7 @@ class ButtonModule implements ModuleInterface
|
||||||
$smartButton->renderWrapper();
|
$smartButton->renderWrapper();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
add_action('wp_enqueue_scripts', function () use ($container) {
|
add_action('wp_enqueue_scripts', static function () use ($container) {
|
||||||
|
|
||||||
$smartButton = $container->get('button.smart-button');
|
$smartButton = $container->get('button.smart-button');
|
||||||
$smartButton->enqueue();
|
$smartButton->enqueue();
|
||||||
|
@ -50,7 +51,7 @@ class ButtonModule implements ModuleInterface
|
||||||
|
|
||||||
add_action(
|
add_action(
|
||||||
'wc_ajax_' . ChangeCartEndpoint::ENDPOINT,
|
'wc_ajax_' . ChangeCartEndpoint::ENDPOINT,
|
||||||
function () use ($container) {
|
static function () use ($container) {
|
||||||
$endpoint = $container->get('button.endpoint.change-cart');
|
$endpoint = $container->get('button.endpoint.change-cart');
|
||||||
/**
|
/**
|
||||||
* @var ChangeCartEndpoint $endpoint
|
* @var ChangeCartEndpoint $endpoint
|
||||||
|
@ -61,7 +62,7 @@ class ButtonModule implements ModuleInterface
|
||||||
|
|
||||||
add_action(
|
add_action(
|
||||||
'wc_ajax_' . ApproveOrderEndpoint::ENDPOINT,
|
'wc_ajax_' . ApproveOrderEndpoint::ENDPOINT,
|
||||||
function () use ($container) {
|
static function () use ($container) {
|
||||||
$endpoint = $container->get('button.endpoint.approve-order');
|
$endpoint = $container->get('button.endpoint.approve-order');
|
||||||
/**
|
/**
|
||||||
* @var ChangeCartEndpoint $endpoint
|
* @var ChangeCartEndpoint $endpoint
|
||||||
|
@ -72,7 +73,7 @@ class ButtonModule implements ModuleInterface
|
||||||
|
|
||||||
add_action(
|
add_action(
|
||||||
'wc_ajax_' . CreateOrderEndpoint::ENDPOINT,
|
'wc_ajax_' . CreateOrderEndpoint::ENDPOINT,
|
||||||
function () use ($container) {
|
static function () use ($container) {
|
||||||
$endpoint = $container->get('button.endpoint.create-order');
|
$endpoint = $container->get('button.endpoint.create-order');
|
||||||
/**
|
/**
|
||||||
* @var ChangeCartEndpoint $endpoint
|
* @var ChangeCartEndpoint $endpoint
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\Button\Endpoint;
|
namespace Inpsyde\PayPalCommerce\Button\Endpoint;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\Button\Endpoint;
|
namespace Inpsyde\PayPalCommerce\Button\Endpoint;
|
||||||
|
@ -30,17 +31,18 @@ class ChangeCartEndpoint implements EndpointInterface
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function nonce() : string
|
public static function nonce(): string
|
||||||
{
|
{
|
||||||
return self::ENDPOINT;
|
return self::ENDPOINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handleRequest() : bool
|
public function handleRequest(): bool
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$data = $this->requestData->readRequest($this->nonce());
|
$data = $this->requestData->readRequest($this->nonce());
|
||||||
|
|
||||||
if (! isset($data['products'])
|
if (
|
||||||
|
! isset($data['products'])
|
||||||
|| ! is_array($data['products'])
|
|| ! is_array($data['products'])
|
||||||
) {
|
) {
|
||||||
wp_send_json_error(
|
wp_send_json_error(
|
||||||
|
@ -95,7 +97,7 @@ class ChangeCartEndpoint implements EndpointInterface
|
||||||
if (count($errors)) {
|
if (count($errors)) {
|
||||||
$message = array_reduce(
|
$message = array_reduce(
|
||||||
$errors,
|
$errors,
|
||||||
function (string $add, array $error) : string {
|
static function (string $add, array $error): string {
|
||||||
return $add . $error['notice'] . ' ';
|
return $add . $error['notice'] . ' ';
|
||||||
},
|
},
|
||||||
''
|
''
|
||||||
|
@ -114,7 +116,7 @@ class ChangeCartEndpoint implements EndpointInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addProduct(\WC_Product $product, int $quantity) : bool
|
private function addProduct(\WC_Product $product, int $quantity): bool
|
||||||
{
|
{
|
||||||
return false !== $this->cart->add_to_cart($product->get_id(), $quantity);
|
return false !== $this->cart->add_to_cart($product->get_id(), $quantity);
|
||||||
}
|
}
|
||||||
|
@ -123,7 +125,7 @@ class ChangeCartEndpoint implements EndpointInterface
|
||||||
\WC_Product $product,
|
\WC_Product $product,
|
||||||
int $quantity,
|
int $quantity,
|
||||||
array $postVariations
|
array $postVariations
|
||||||
) : bool {
|
): bool {
|
||||||
|
|
||||||
foreach ($postVariations as $key => $value) {
|
foreach ($postVariations as $key => $value) {
|
||||||
$variations[$value['name']] = $value['value'];
|
$variations[$value['name']] = $value['value'];
|
||||||
|
@ -136,10 +138,10 @@ class ChangeCartEndpoint implements EndpointInterface
|
||||||
return false !== WC()->cart->add_to_cart($product->get_id(), $quantity, $variationId, $variations);
|
return false !== WC()->cart->add_to_cart($product->get_id(), $quantity, $variationId, $variations);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function generatePurchaseUnits() : array
|
private function generatePurchaseUnits(): array
|
||||||
{
|
{
|
||||||
return array_map(
|
return array_map(
|
||||||
function (PurchaseUnit $lineItem) : array {
|
static function (PurchaseUnit $lineItem): array {
|
||||||
return $lineItem->toArray();
|
return $lineItem->toArray();
|
||||||
},
|
},
|
||||||
$this->repository->all()
|
$this->repository->all()
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\Button\Endpoint;
|
namespace Inpsyde\PayPalCommerce\Button\Endpoint;
|
||||||
|
@ -30,12 +31,12 @@ class CreateOrderEndpoint implements EndpointInterface
|
||||||
$this->payerFactory = $payerFactory;
|
$this->payerFactory = $payerFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function nonce() : string
|
public static function nonce(): string
|
||||||
{
|
{
|
||||||
return self::ENDPOINT;
|
return self::ENDPOINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handleRequest() : bool
|
public function handleRequest(): bool
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$data = $this->requestData->readRequest($this->nonce());
|
$data = $this->requestData->readRequest($this->nonce());
|
||||||
|
@ -46,7 +47,7 @@ class CreateOrderEndpoint implements EndpointInterface
|
||||||
// make sure the phone number contains only numbers and is max 14. chars long.
|
// make sure the phone number contains only numbers and is max 14. chars long.
|
||||||
$number = $data['payer']['phone']['phone_number']['national_number'];
|
$number = $data['payer']['phone']['phone_number']['national_number'];
|
||||||
$number = preg_replace("/[^0-9]/", "", $number);
|
$number = preg_replace("/[^0-9]/", "", $number);
|
||||||
$number = substr($number,0,14);
|
$number = substr($number, 0, 14);
|
||||||
$data['payer']['phone']['phone_number']['national_number'] = $number;
|
$data['payer']['phone']['phone_number']['national_number'] = $number;
|
||||||
}
|
}
|
||||||
$payer = $this->payerFactory->fromPayPalResponse(json_decode(json_encode($data['payer'])));
|
$payer = $this->payerFactory->fromPayPalResponse(json_decode(json_encode($data['payer'])));
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\Button\Endpoint;
|
namespace Inpsyde\PayPalCommerce\Button\Endpoint;
|
||||||
|
@ -6,7 +7,7 @@ namespace Inpsyde\PayPalCommerce\Button\Endpoint;
|
||||||
interface EndpointInterface
|
interface EndpointInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
public static function nonce() : string;
|
public static function nonce(): string;
|
||||||
|
|
||||||
public function handleRequest() : bool;
|
public function handleRequest(): bool;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\Button\Endpoint;
|
namespace Inpsyde\PayPalCommerce\Button\Endpoint;
|
||||||
|
@ -8,11 +9,12 @@ use Inpsyde\PayPalCommerce\Button\Exception\RuntimeException;
|
||||||
class RequestData
|
class RequestData
|
||||||
{
|
{
|
||||||
|
|
||||||
public function readRequest(string $nonce) : array
|
public function readRequest(string $nonce): array
|
||||||
{
|
{
|
||||||
$stream = file_get_contents('php://input');
|
$stream = file_get_contents('php://input');
|
||||||
$json = json_decode($stream, true);
|
$json = json_decode($stream, true);
|
||||||
if (! isset($json['nonce'])
|
if (
|
||||||
|
! isset($json['nonce'])
|
||||||
|| !wp_verify_nonce($json['nonce'], $nonce)
|
|| !wp_verify_nonce($json['nonce'], $nonce)
|
||||||
) {
|
) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
|
@ -23,7 +25,7 @@ class RequestData
|
||||||
return $this->sanitize($json);
|
return $this->sanitize($json);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function sanitize(array $assocArray) : array
|
private function sanitize(array $assocArray): array
|
||||||
{
|
{
|
||||||
$data = [];
|
$data = [];
|
||||||
foreach ((array) $assocArray as $rawKey => $rawValue) {
|
foreach ((array) $assocArray as $rawKey => $rawValue) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\Button\Exception;
|
namespace Inpsyde\PayPalCommerce\Button\Exception;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\WcGateway;
|
namespace Inpsyde\PayPalCommerce\WcGateway;
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\WcGateway;
|
namespace Inpsyde\PayPalCommerce\WcGateway;
|
||||||
|
|
||||||
use Dhii\Modular\Module\ModuleInterface;
|
use Dhii\Modular\Module\ModuleInterface;
|
||||||
|
|
||||||
return function (): ModuleInterface {
|
return static function (): ModuleInterface {
|
||||||
return new WcGatewayModule();
|
return new WcGatewayModule();
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,10 +19,10 @@ use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
|
||||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsFields;
|
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsFields;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'wcgateway.gateway.base' => function (ContainerInterface $container) : WcGatewayBase {
|
'wcgateway.gateway.base' => static function (ContainerInterface $container): WcGatewayBase {
|
||||||
return new WcGatewayBase();
|
return new WcGatewayBase();
|
||||||
},
|
},
|
||||||
'wcgateway.gateway' => function (ContainerInterface $container) : WcGateway {
|
'wcgateway.gateway' => static function (ContainerInterface $container): WcGateway {
|
||||||
$sessionHandler = $container->get('session.handler');
|
$sessionHandler = $container->get('session.handler');
|
||||||
$cartRepository = $container->get('api.repository.cart');
|
$cartRepository = $container->get('api.repository.cart');
|
||||||
// TODO eventuall get rid of the endpoints as the processor is sufficient
|
// TODO eventuall get rid of the endpoints as the processor is sufficient
|
||||||
|
@ -31,6 +31,7 @@ return [
|
||||||
$orderFactory = $container->get('api.factory.order');
|
$orderFactory = $container->get('api.factory.order');
|
||||||
$settingsFields = $container->get('wcgateway.settings.fields');
|
$settingsFields = $container->get('wcgateway.settings.fields');
|
||||||
$processor = $container->get('wcgateway.processor');
|
$processor = $container->get('wcgateway.processor');
|
||||||
|
$notice = $container->get('wcgateway.notice.authorize-order-action');
|
||||||
return new WcGateway(
|
return new WcGateway(
|
||||||
$sessionHandler,
|
$sessionHandler,
|
||||||
$cartRepository,
|
$cartRepository,
|
||||||
|
@ -38,43 +39,44 @@ return [
|
||||||
$paymentsEndpoint,
|
$paymentsEndpoint,
|
||||||
$orderFactory,
|
$orderFactory,
|
||||||
$settingsFields,
|
$settingsFields,
|
||||||
$processor
|
$processor,
|
||||||
|
$notice
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'wcgateway.disabler' => function (ContainerInterface $container) : DisableGateways {
|
'wcgateway.disabler' => static function (ContainerInterface $container): DisableGateways {
|
||||||
$sessionHandler = $container->get('session.handler');
|
$sessionHandler = $container->get('session.handler');
|
||||||
return new DisableGateways($sessionHandler);
|
return new DisableGateways($sessionHandler);
|
||||||
},
|
},
|
||||||
'wcgateway.settings' => function (ContainerInterface $container) : Settings {
|
'wcgateway.settings' => static function (ContainerInterface $container): Settings {
|
||||||
$gateway = $container->get('wcgateway.gateway.base');
|
$gateway = $container->get('wcgateway.gateway.base');
|
||||||
$settingsField = $container->get('wcgateway.settings.fields');
|
$settingsField = $container->get('wcgateway.settings.fields');
|
||||||
return new Settings($gateway, $settingsField);
|
return new Settings($gateway, $settingsField);
|
||||||
},
|
},
|
||||||
'wcgateway.notice.connect' => function (ContainerInterface $container) : ConnectAdminNotice {
|
'wcgateway.notice.connect' => static function (ContainerInterface $container): ConnectAdminNotice {
|
||||||
$settings = $container->get('wcgateway.settings');
|
$settings = $container->get('wcgateway.settings');
|
||||||
return new ConnectAdminNotice($settings);
|
return new ConnectAdminNotice($settings);
|
||||||
},
|
},
|
||||||
'wcgateway.notice.authorize-order-action' =>
|
'wcgateway.notice.authorize-order-action' =>
|
||||||
function (ContainerInterface $container): AuthorizeOrderActionNotice {
|
static function (ContainerInterface $container): AuthorizeOrderActionNotice {
|
||||||
return new AuthorizeOrderActionNotice();
|
return new AuthorizeOrderActionNotice();
|
||||||
},
|
},
|
||||||
'wcgateway.settings.fields' => function (ContainerInterface $container): SettingsFields {
|
'wcgateway.settings.fields' => static function (ContainerInterface $container): SettingsFields {
|
||||||
return new SettingsFields();
|
return new SettingsFields();
|
||||||
},
|
},
|
||||||
'wcgateway.processor' => function (ContainerInterface $container): Processor {
|
'wcgateway.processor' => static function (ContainerInterface $container): Processor {
|
||||||
$authorizedPaymentsProcessor = $container->get('wcgateway.processor.authorized-payments');
|
$authorizedPaymentsProcessor = $container->get('wcgateway.processor.authorized-payments');
|
||||||
return new Processor($authorizedPaymentsProcessor);
|
return new Processor($authorizedPaymentsProcessor);
|
||||||
},
|
},
|
||||||
'wcgateway.processor.authorized-payments' => function (ContainerInterface $container): AuthorizedPaymentsProcessor {
|
'wcgateway.processor.authorized-payments' => static function (ContainerInterface $container): AuthorizedPaymentsProcessor {
|
||||||
$orderEndpoint = $container->get('api.endpoint.order');
|
$orderEndpoint = $container->get('api.endpoint.order');
|
||||||
$paymentsEndpoint = $container->get('api.endpoint.payments');
|
$paymentsEndpoint = $container->get('api.endpoint.payments');
|
||||||
return new AuthorizedPaymentsProcessor($orderEndpoint, $paymentsEndpoint);
|
return new AuthorizedPaymentsProcessor($orderEndpoint, $paymentsEndpoint);
|
||||||
},
|
},
|
||||||
'wcgateway.admin.order-payment-status' => function(ContainerInterface $container): PaymentStatusOrderDetail {
|
'wcgateway.admin.order-payment-status' => static function (ContainerInterface $container): PaymentStatusOrderDetail {
|
||||||
return new PaymentStatusOrderDetail();
|
return new PaymentStatusOrderDetail();
|
||||||
},
|
},
|
||||||
'wcgateway.admin.orders-payment-status-column' => function(ContainerInterface $container): OrderTablePaymentStatusColumn {
|
'wcgateway.admin.orders-payment-status-column' => static function (ContainerInterface $container): OrderTablePaymentStatusColumn {
|
||||||
$settings = $container->get('wcgateway.settings');
|
$settings = $container->get('wcgateway.settings');
|
||||||
return new OrderTablePaymentStatusColumn($settings);
|
return new OrderTablePaymentStatusColumn($settings);
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -4,14 +4,15 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\WcGateway\Admin;
|
namespace Inpsyde\PayPalCommerce\WcGateway\Admin;
|
||||||
|
|
||||||
|
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
|
||||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
|
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
|
||||||
|
|
||||||
class OrderTablePaymentStatusColumn
|
class OrderTablePaymentStatusColumn
|
||||||
{
|
{
|
||||||
const COLUMN_KEY = 'ppcp_payment_status';
|
private const COLUMN_KEY = 'ppcp_payment_status';
|
||||||
const INTENT = 'authorize';
|
private const INTENT = 'authorize';
|
||||||
const AFTER_COLUMN_KEY = 'order_status';
|
private const AFTER_COLUMN_KEY = 'order_status';
|
||||||
protected $settings;
|
private $settings;
|
||||||
|
|
||||||
public function __construct(Settings $settings)
|
public function __construct(Settings $settings)
|
||||||
{
|
{
|
||||||
|
@ -48,31 +49,36 @@ class OrderTablePaymentStatusColumn
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->isCaptured($wcOrderId)) {
|
$wcOrder = wc_get_order($wcOrderId);
|
||||||
|
|
||||||
|
if (! is_a($wcOrder, \WC_Order::class) || ! $this->renderForOrder($wcOrder)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->isCaptured($wcOrder)) {
|
||||||
$this->renderCompletedStatus();
|
$this->renderCompletedStatus();
|
||||||
} else {
|
} else {
|
||||||
$this->renderIncompletedStatus();
|
$this->renderIncompletedStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isCaptured(int $wcOrderId): bool
|
private function renderForOrder(\WC_Order $order): bool
|
||||||
{
|
{
|
||||||
$wcOrder = wc_get_order($wcOrderId);
|
return !empty($order->get_meta(WcGateway::CAPTURED_META_KEY));
|
||||||
$captured = $wcOrder->get_meta('_ppcp_paypal_captured');
|
|
||||||
|
|
||||||
if (!empty($captured) && wc_string_to_bool($captured)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function renderCompletedStatus()
|
private function isCaptured(\WC_Order $wcOrder): bool
|
||||||
|
{
|
||||||
|
$captured = $wcOrder->get_meta(WcGateway::CAPTURED_META_KEY);
|
||||||
|
return wc_string_to_bool($captured);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function renderCompletedStatus()
|
||||||
{
|
{
|
||||||
echo '<span class="dashicons dashicons-yes"></span>';
|
echo '<span class="dashicons dashicons-yes"></span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function renderIncompletedStatus()
|
private function renderIncompletedStatus()
|
||||||
{
|
{
|
||||||
printf(
|
printf(
|
||||||
'<mark class="onbackorder">%s</mark>',
|
'<mark class="onbackorder">%s</mark>',
|
||||||
|
|
|
@ -4,13 +4,15 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\WcGateway\Admin;
|
namespace Inpsyde\PayPalCommerce\WcGateway\Admin;
|
||||||
|
|
||||||
|
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
|
||||||
|
|
||||||
class PaymentStatusOrderDetail
|
class PaymentStatusOrderDetail
|
||||||
{
|
{
|
||||||
public function render(int $wcOrderId)
|
public function render(int $wcOrderId)
|
||||||
{
|
{
|
||||||
$wcOrder = new \WC_Order($wcOrderId);
|
$wcOrder = new \WC_Order($wcOrderId);
|
||||||
$intent = $wcOrder->get_meta('_ppcp_paypal_intent');
|
$intent = $wcOrder->get_meta(WcGateway::INTENT_META_KEY);
|
||||||
$captured = $wcOrder->get_meta('_ppcp_paypal_captured');
|
$captured = $wcOrder->get_meta(WcGateway::CAPTURED_META_KEY);
|
||||||
|
|
||||||
if (strcasecmp($intent, 'AUTHORIZE') !== 0) {
|
if (strcasecmp($intent, 'AUTHORIZE') !== 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -23,8 +25,14 @@ class PaymentStatusOrderDetail
|
||||||
printf(
|
printf(
|
||||||
// @phpcs:ignore Inpsyde.CodeQuality.LineLength.TooLong
|
// @phpcs:ignore Inpsyde.CodeQuality.LineLength.TooLong
|
||||||
'<li class="wide"><p><mark class="order-status status-on-hold"><span>%1$s</span></mark></p><p>%2$s</p></li>',
|
'<li class="wide"><p><mark class="order-status status-on-hold"><span>%1$s</span></mark></p><p>%2$s</p></li>',
|
||||||
esc_html__('Not captured', 'woocommerce-paypal-gateway'),
|
esc_html__(
|
||||||
esc_html__('To capture the payment select capture action from the list below.', 'woocommerce-paypal-gateway'),
|
'Not captured',
|
||||||
|
'woocommerce-paypal-gateway'
|
||||||
|
),
|
||||||
|
esc_html__(
|
||||||
|
'To capture the payment select capture action from the list below.',
|
||||||
|
'woocommerce-paypal-gateway'
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\WcGateway\Checkout;
|
namespace Inpsyde\PayPalCommerce\WcGateway\Checkout;
|
||||||
|
@ -15,7 +16,7 @@ class DisableGateways
|
||||||
$this->sessionHandler = $sessionHandler;
|
$this->sessionHandler = $sessionHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handler(array $methods) : array
|
public function handler(array $methods): array
|
||||||
{
|
{
|
||||||
if (! $this->needsToDisableGateways()) {
|
if (! $this->needsToDisableGateways()) {
|
||||||
return $methods;
|
return $methods;
|
||||||
|
@ -24,7 +25,7 @@ class DisableGateways
|
||||||
return [WcGateway::ID => $methods[WcGateway::ID]];
|
return [WcGateway::ID => $methods[WcGateway::ID]];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function needsToDisableGateways() : bool
|
private function needsToDisableGateways(): bool
|
||||||
{
|
{
|
||||||
return $this->sessionHandler->order() !== null;
|
return $this->sessionHandler->order() !== null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\WcGateway\Exception;
|
namespace Inpsyde\PayPalCommerce\WcGateway\Exception;
|
||||||
|
|
|
@ -12,6 +12,7 @@ use Inpsyde\PayPalCommerce\ApiClient\Factory\OrderFactory;
|
||||||
use Inpsyde\PayPalCommerce\ApiClient\Repository\CartRepository;
|
use Inpsyde\PayPalCommerce\ApiClient\Repository\CartRepository;
|
||||||
use Inpsyde\PayPalCommerce\Session\SessionHandler;
|
use Inpsyde\PayPalCommerce\Session\SessionHandler;
|
||||||
use Inpsyde\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
|
use Inpsyde\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
|
||||||
|
use Inpsyde\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
|
||||||
use Inpsyde\PayPalCommerce\WcGateway\Processor\Processor;
|
use Inpsyde\PayPalCommerce\WcGateway\Processor\Processor;
|
||||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsFields;
|
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsFields;
|
||||||
|
|
||||||
|
@ -19,6 +20,11 @@ use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsFields;
|
||||||
//phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
|
//phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
|
||||||
class WcGateway extends WcGatewayBase implements WcGatewayInterface
|
class WcGateway extends WcGatewayBase implements WcGatewayInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public const CAPTURED_META_KEY = '_ppcp_paypal_captured';
|
||||||
|
public const INTENT_META_KEY = '_ppcp_paypal_intent';
|
||||||
|
public const ORDER_ID_META_KEY = '_ppcp_paypal_order_id';
|
||||||
|
|
||||||
private $isSandbox = true;
|
private $isSandbox = true;
|
||||||
private $sessionHandler;
|
private $sessionHandler;
|
||||||
private $orderEndpoint;
|
private $orderEndpoint;
|
||||||
|
@ -27,6 +33,7 @@ class WcGateway extends WcGatewayBase implements WcGatewayInterface
|
||||||
private $settingsFields;
|
private $settingsFields;
|
||||||
private $paymentsEndpoint;
|
private $paymentsEndpoint;
|
||||||
private $processor;
|
private $processor;
|
||||||
|
private $notice;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
SessionHandler $sessionHandler,
|
SessionHandler $sessionHandler,
|
||||||
|
@ -35,8 +42,10 @@ class WcGateway extends WcGatewayBase implements WcGatewayInterface
|
||||||
PaymentsEndpoint $paymentsEndpoint,
|
PaymentsEndpoint $paymentsEndpoint,
|
||||||
OrderFactory $orderFactory,
|
OrderFactory $orderFactory,
|
||||||
SettingsFields $settingsFields,
|
SettingsFields $settingsFields,
|
||||||
Processor $processor
|
Processor $processor,
|
||||||
|
AuthorizeOrderActionNotice $notice
|
||||||
) {
|
) {
|
||||||
|
|
||||||
$this->sessionHandler = $sessionHandler;
|
$this->sessionHandler = $sessionHandler;
|
||||||
$this->cartRepository = $cartRepository;
|
$this->cartRepository = $cartRepository;
|
||||||
$this->orderEndpoint = $orderEndpoint;
|
$this->orderEndpoint = $orderEndpoint;
|
||||||
|
@ -44,6 +53,7 @@ class WcGateway extends WcGatewayBase implements WcGatewayInterface
|
||||||
$this->orderFactory = $orderFactory;
|
$this->orderFactory = $orderFactory;
|
||||||
$this->settingsFields = $settingsFields;
|
$this->settingsFields = $settingsFields;
|
||||||
$this->processor = $processor;
|
$this->processor = $processor;
|
||||||
|
$this->notice = $notice;
|
||||||
|
|
||||||
$this->method_title = __('PayPal Payments', 'woocommerce-paypal-gateway');
|
$this->method_title = __('PayPal Payments', 'woocommerce-paypal-gateway');
|
||||||
$this->method_description = __(
|
$this->method_description = __(
|
||||||
|
@ -79,8 +89,8 @@ class WcGateway extends WcGatewayBase implements WcGatewayInterface
|
||||||
$wcOrder = new \WC_Order($orderId);
|
$wcOrder = new \WC_Order($orderId);
|
||||||
|
|
||||||
$order = $this->sessionHandler->order();
|
$order = $this->sessionHandler->order();
|
||||||
$wcOrder->update_meta_data('_ppcp_paypal_order_id', $order->id());
|
$wcOrder->update_meta_data(self::ORDER_ID_META_KEY, $order->id());
|
||||||
$wcOrder->update_meta_data('_ppcp_paypal_intent', $order->intent());
|
$wcOrder->update_meta_data(self::INTENT_META_KEY, $order->intent());
|
||||||
|
|
||||||
$errorMessage = null;
|
$errorMessage = null;
|
||||||
if (!$order || !$order->status()->is(OrderStatus::APPROVED)) {
|
if (!$order || !$order->status()->is(OrderStatus::APPROVED)) {
|
||||||
|
@ -92,7 +102,7 @@ class WcGateway extends WcGatewayBase implements WcGatewayInterface
|
||||||
__('Payment error: %s', 'woocommerce-paypal-gateway'),
|
__('Payment error: %s', 'woocommerce-paypal-gateway'),
|
||||||
$errorMessage
|
$errorMessage
|
||||||
);
|
);
|
||||||
wc_add_notice( $notice, 'error');
|
wc_add_notice($notice, 'error');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,6 +113,7 @@ class WcGateway extends WcGatewayBase implements WcGatewayInterface
|
||||||
|
|
||||||
if ($order->intent() === 'AUTHORIZE') {
|
if ($order->intent() === 'AUTHORIZE') {
|
||||||
$order = $this->orderEndpoint->authorize($order);
|
$order = $this->orderEndpoint->authorize($order);
|
||||||
|
$wcOrder->update_meta_data(self::CAPTURED_META_KEY, 'false');
|
||||||
}
|
}
|
||||||
|
|
||||||
$wcOrder->update_status('on-hold', __('Awaiting payment.', 'woocommerce-paypal-gateway'));
|
$wcOrder->update_status('on-hold', __('Awaiting payment.', 'woocommerce-paypal-gateway'));
|
||||||
|
@ -122,14 +133,14 @@ class WcGateway extends WcGatewayBase implements WcGatewayInterface
|
||||||
{
|
{
|
||||||
$result = $this->processor->authorizedPayments()->process($wcOrder);
|
$result = $this->processor->authorizedPayments()->process($wcOrder);
|
||||||
|
|
||||||
if ($result === 'INACCESSIBLE') {
|
if ($result === AuthorizedPaymentsProcessor::INACCESSIBLE) {
|
||||||
AuthorizeOrderActionNotice::displayMessage(AuthorizeOrderActionNotice::NO_INFO);
|
$this->notice->displayMessage(AuthorizeOrderActionNotice::NO_INFO);
|
||||||
}
|
}
|
||||||
if ($result === 'NOT_FOUND') {
|
if ($result === AuthorizedPaymentsProcessor::NOT_FOUND) {
|
||||||
AuthorizeOrderActionNotice::displayMessage(AuthorizeOrderActionNotice::NOT_FOUND);
|
$this->notice->displayMessage(AuthorizeOrderActionNotice::NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result === 'ALREADY_CAPTURED') {
|
if ($result === AuthorizedPaymentsProcessor::ALREADY_CAPTURED) {
|
||||||
if ($wcOrder->get_status() === 'on-hold') {
|
if ($wcOrder->get_status() === 'on-hold') {
|
||||||
$wcOrder->add_order_note(
|
$wcOrder->add_order_note(
|
||||||
__(
|
__(
|
||||||
|
@ -138,19 +149,19 @@ class WcGateway extends WcGatewayBase implements WcGatewayInterface
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$wcOrder->update_status('processing');
|
$wcOrder->update_status('processing');
|
||||||
$wcOrder->update_meta_data('_ppcp_paypal_captured', 'true');
|
$wcOrder->update_meta_data(self::CAPTURED_META_KEY, 'true');
|
||||||
// TODO investigate why save has to be called
|
// TODO investigate why save has to be called
|
||||||
$wcOrder->save();
|
$wcOrder->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
AuthorizeOrderActionNotice::displayMessage(AuthorizeOrderActionNotice::ALREADY_CAPTURED);
|
$this->notice->displayMessage(AuthorizeOrderActionNotice::ALREADY_CAPTURED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result === 'FAILED') {
|
if ($result === AuthorizedPaymentsProcessor::FAILED) {
|
||||||
AuthorizeOrderActionNotice::displayMessage(AuthorizeOrderActionNotice::FAILED);
|
$this->notice->displayMessage(AuthorizeOrderActionNotice::FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result === 'SUCCESSFUL') {
|
if ($result === AuthorizedPaymentsProcessor::SUCCESSFUL) {
|
||||||
$wcOrder->add_order_note(
|
$wcOrder->add_order_note(
|
||||||
__(
|
__(
|
||||||
'Payment successfully captured.',
|
'Payment successfully captured.',
|
||||||
|
@ -159,11 +170,11 @@ class WcGateway extends WcGatewayBase implements WcGatewayInterface
|
||||||
);
|
);
|
||||||
|
|
||||||
$wcOrder->update_status('processing');
|
$wcOrder->update_status('processing');
|
||||||
$wcOrder->update_meta_data('_ppcp_paypal_captured', 'true');
|
$wcOrder->update_meta_data(self::CAPTURED_META_KEY, 'true');
|
||||||
// TODO investigate why save has to be called
|
// TODO investigate why save has to be called
|
||||||
$wcOrder->save();
|
$wcOrder->save();
|
||||||
|
|
||||||
AuthorizeOrderActionNotice::displayMessage(AuthorizeOrderActionNotice::SUCCESS);
|
$this->notice->displayMessage(AuthorizeOrderActionNotice::SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\WcGateway\Gateway;
|
namespace Inpsyde\PayPalCommerce\WcGateway\Gateway;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\WcGateway\Gateway;
|
namespace Inpsyde\PayPalCommerce\WcGateway\Gateway;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\WcGateway\Notice;
|
namespace Inpsyde\PayPalCommerce\WcGateway\Notice;
|
||||||
|
@ -7,16 +8,18 @@ use Inpsyde\PayPalCommerce\AdminNotices\Entity\Message;
|
||||||
|
|
||||||
class AuthorizeOrderActionNotice
|
class AuthorizeOrderActionNotice
|
||||||
{
|
{
|
||||||
const QUERY_PARAM = 'ppcp-authorized-message';
|
public const QUERY_PARAM = 'ppcp-authorized-message';
|
||||||
|
|
||||||
const NO_INFO = 81;
|
public const NO_INFO = 81;
|
||||||
const ALREADY_CAPTURED = 82;
|
public const ALREADY_CAPTURED = 82;
|
||||||
const FAILED = 83;
|
public const FAILED = 83;
|
||||||
const SUCCESS = 84;
|
public const SUCCESS = 84;
|
||||||
const NOT_FOUND = 85;
|
public const NOT_FOUND = 85;
|
||||||
|
|
||||||
public function message() : ?Message {
|
public function message(): ?Message
|
||||||
$message = $this->getMessage();
|
{
|
||||||
|
|
||||||
|
$message = $this->currentMessage();
|
||||||
if (! $message) {
|
if (! $message) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +27,7 @@ class AuthorizeOrderActionNotice
|
||||||
return new Message($message['message'], $message['type']);
|
return new Message($message['message'], $message['type']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMessage(): array
|
private function currentMessage(): array
|
||||||
{
|
{
|
||||||
$messages[self::NO_INFO] = [
|
$messages[self::NO_INFO] = [
|
||||||
'message' => __(
|
'message' => __(
|
||||||
|
@ -62,18 +65,20 @@ class AuthorizeOrderActionNotice
|
||||||
'type' => 'success',
|
'type' => 'success',
|
||||||
];
|
];
|
||||||
|
|
||||||
if (! isset($_GET['ppcp-message'])) {
|
//phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||||
|
if (! isset($_GET[self::QUERY_PARAM])) { // Input ok.
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
$messageId = absint($_GET[self::QUERY_PARAM]);
|
$messageId = absint($_GET[self::QUERY_PARAM]); // Input ok.
|
||||||
|
//phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||||
return (isset($messages[$messageId])) ? $messages[$messageId] : [];
|
return (isset($messages[$messageId])) ? $messages[$messageId] : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function displayMessage(int $messageCode): void
|
public function displayMessage(int $messageCode): void
|
||||||
{
|
{
|
||||||
add_filter(
|
add_filter(
|
||||||
'redirect_post_location',
|
'redirect_post_location',
|
||||||
function ($location) use ($messageCode) {
|
static function ($location) use ($messageCode) {
|
||||||
return add_query_arg(
|
return add_query_arg(
|
||||||
self::QUERY_PARAM,
|
self::QUERY_PARAM,
|
||||||
$messageCode,
|
$messageCode,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\WcGateway\Notice;
|
namespace Inpsyde\PayPalCommerce\WcGateway\Notice;
|
||||||
|
@ -15,7 +16,7 @@ class ConnectAdminNotice
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function connectMessage() : ?Message
|
public function connectMessage(): ?Message
|
||||||
{
|
{
|
||||||
if (!$this->shouldDisplay()) {
|
if (!$this->shouldDisplay()) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -31,7 +32,7 @@ class ConnectAdminNotice
|
||||||
// TODO: find a better way to get the url
|
// TODO: find a better way to get the url
|
||||||
admin_url('admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway')
|
admin_url('admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway')
|
||||||
);
|
);
|
||||||
return new Message( $message, 'warning');
|
return new Message($message, 'warning');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function shouldDisplay(): bool
|
protected function shouldDisplay(): bool
|
||||||
|
|
|
@ -10,6 +10,7 @@ use Inpsyde\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint;
|
||||||
use Inpsyde\PayPalCommerce\ApiClient\Entity\Authorization;
|
use Inpsyde\PayPalCommerce\ApiClient\Entity\Authorization;
|
||||||
use Inpsyde\PayPalCommerce\ApiClient\Entity\AuthorizationStatus;
|
use Inpsyde\PayPalCommerce\ApiClient\Entity\AuthorizationStatus;
|
||||||
use Inpsyde\PayPalCommerce\ApiClient\Entity\Order;
|
use Inpsyde\PayPalCommerce\ApiClient\Entity\Order;
|
||||||
|
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
|
||||||
|
|
||||||
class AuthorizedPaymentsProcessor
|
class AuthorizedPaymentsProcessor
|
||||||
{
|
{
|
||||||
|
@ -25,16 +26,15 @@ class AuthorizedPaymentsProcessor
|
||||||
OrderEndpoint $orderEndpoint,
|
OrderEndpoint $orderEndpoint,
|
||||||
PaymentsEndpoint $paymentsEndpoint
|
PaymentsEndpoint $paymentsEndpoint
|
||||||
) {
|
) {
|
||||||
|
|
||||||
$this->orderEndpoint = $orderEndpoint;
|
$this->orderEndpoint = $orderEndpoint;
|
||||||
$this->paymentsEndpoint = $paymentsEndpoint;
|
$this->paymentsEndpoint = $paymentsEndpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function process(\WC_Order $wcOrder): string
|
public function process(\WC_Order $wcOrder): string
|
||||||
{
|
{
|
||||||
$orderId = $this->getPayPalOrderId($wcOrder);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$order = $this->getCurrentOrderInfo($orderId);
|
$order = $this->payPalOrderFromWcOrder($wcOrder);
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
if ($exception->getCode() === 404) {
|
if ($exception->getCode() === 404) {
|
||||||
return self::NOT_FOUND;
|
return self::NOT_FOUND;
|
||||||
|
@ -42,7 +42,7 @@ class AuthorizedPaymentsProcessor
|
||||||
return self::INACCESSIBLE;
|
return self::INACCESSIBLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
$authorizations = $this->getAllAuthorizations($order);
|
$authorizations = $this->allAuthorizations($order);
|
||||||
|
|
||||||
if (!$this->areAuthorizationToCapture(...$authorizations)) {
|
if (!$this->areAuthorizationToCapture(...$authorizations)) {
|
||||||
return self::ALREADY_CAPTURED;
|
return self::ALREADY_CAPTURED;
|
||||||
|
@ -57,17 +57,13 @@ class AuthorizedPaymentsProcessor
|
||||||
return self::SUCCESSFUL;
|
return self::SUCCESSFUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getPayPalOrderId(\WC_Order $wcOrder): string
|
protected function payPalOrderFromWcOrder(\WC_Order $wcOrder): Order
|
||||||
{
|
|
||||||
return $wcOrder->get_meta('_ppcp_paypal_order_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getCurrentOrderInfo(string $orderId): Order
|
|
||||||
{
|
{
|
||||||
|
$orderId = $wcOrder->get_meta(WcGateway::ORDER_ID_META_KEY);
|
||||||
return $this->orderEndpoint->order($orderId);
|
return $this->orderEndpoint->order($orderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getAllAuthorizations(Order $order): array
|
protected function allAuthorizations(Order $order): array
|
||||||
{
|
{
|
||||||
$authorizations = [];
|
$authorizations = [];
|
||||||
foreach ($order->purchaseUnits() as $purchaseUnit) {
|
foreach ($order->purchaseUnits() as $purchaseUnit) {
|
||||||
|
@ -102,7 +98,7 @@ class AuthorizedPaymentsProcessor
|
||||||
{
|
{
|
||||||
return array_filter(
|
return array_filter(
|
||||||
$authorizations,
|
$authorizations,
|
||||||
function (Authorization $authorization) {
|
static function (Authorization $authorization): bool {
|
||||||
return $authorization->status()->is(AuthorizationStatus::CREATED);
|
return $authorization->status()->is(AuthorizationStatus::CREATED);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -115,7 +111,7 @@ class AuthorizedPaymentsProcessor
|
||||||
{
|
{
|
||||||
return array_filter(
|
return array_filter(
|
||||||
$authorizations,
|
$authorizations,
|
||||||
function (Authorization $authorization) {
|
static function (Authorization $authorization): bool {
|
||||||
return $authorization->status()->is(AuthorizationStatus::CAPTURED);
|
return $authorization->status()->is(AuthorizationStatus::CAPTURED);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -13,7 +13,9 @@ class Processor
|
||||||
$this->authorizedPaymentsProcessor = $authorizedPaymentsProcessor;
|
$this->authorizedPaymentsProcessor = $authorizedPaymentsProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function authorizedPayments() {
|
public function authorizedPayments(): AuthorizedPaymentsProcessor
|
||||||
|
{
|
||||||
|
|
||||||
return $this->authorizedPaymentsProcessor;
|
return $this->authorizedPaymentsProcessor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Inpsyde\PayPalCommerce\WcGateway\Settings;
|
namespace Inpsyde\PayPalCommerce\WcGateway\Settings;
|
||||||
|
|
||||||
|
//phpcs:disable Inpsyde.CodeQuality.FunctionLength.TooLong
|
||||||
|
|
||||||
class SettingsFields
|
class SettingsFields
|
||||||
{
|
{
|
||||||
public function fields(): array
|
public function fields(): array
|
||||||
|
@ -15,7 +17,7 @@ class SettingsFields
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function gateway()
|
protected function gateway(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'enabled' => [
|
'enabled' => [
|
||||||
|
@ -65,7 +67,7 @@ class SettingsFields
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function account()
|
private function account(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'account_settings' => [
|
'account_settings' => [
|
||||||
|
@ -85,7 +87,7 @@ class SettingsFields
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buttons()
|
private function buttons(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'button_settings' => [
|
'button_settings' => [
|
||||||
|
@ -168,8 +170,8 @@ class SettingsFields
|
||||||
'mybank' => _x('MyBank', 'Name of payment method', 'woocommerce-paypal-gateway'),
|
'mybank' => _x('MyBank', 'Name of payment method', 'woocommerce-paypal-gateway'),
|
||||||
'p24' => _x('Przelewy24', 'Name of payment method', 'woocommerce-paypal-gateway'),
|
'p24' => _x('Przelewy24', 'Name of payment method', 'woocommerce-paypal-gateway'),
|
||||||
'sofort' => _x('Sofort', 'Name of payment method', 'woocommerce-paypal-gateway'),
|
'sofort' => _x('Sofort', 'Name of payment method', 'woocommerce-paypal-gateway'),
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ class WcGatewayModule implements ModuleInterface
|
||||||
{
|
{
|
||||||
add_filter(
|
add_filter(
|
||||||
'woocommerce_payment_gateways',
|
'woocommerce_payment_gateways',
|
||||||
function ($methods) use ($container) : array {
|
static function ($methods) use ($container): array {
|
||||||
$methods[] = $container->get('wcgateway.gateway');
|
$methods[] = $container->get('wcgateway.gateway');
|
||||||
return (array)$methods;
|
return (array)$methods;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ class WcGatewayModule implements ModuleInterface
|
||||||
|
|
||||||
add_filter(
|
add_filter(
|
||||||
'woocommerce_available_payment_gateways',
|
'woocommerce_available_payment_gateways',
|
||||||
function ($methods) use ($container) : array {
|
static function ($methods) use ($container): array {
|
||||||
$disabler = $container->get('wcgateway.disabler');
|
$disabler = $container->get('wcgateway.disabler');
|
||||||
/**
|
/**
|
||||||
* @var DisableGateways $disabler
|
* @var DisableGateways $disabler
|
||||||
|
@ -50,7 +50,7 @@ class WcGatewayModule implements ModuleInterface
|
||||||
|
|
||||||
add_filter(
|
add_filter(
|
||||||
Repository::NOTICES_FILTER,
|
Repository::NOTICES_FILTER,
|
||||||
function ($notices) use ($container) : array {
|
static function ($notices) use ($container): array {
|
||||||
$notice = $container->get('wcgateway.notice.connect');
|
$notice = $container->get('wcgateway.notice.connect');
|
||||||
/**
|
/**
|
||||||
* @var ConnectAdminNotice $notice
|
* @var ConnectAdminNotice $notice
|
||||||
|
@ -71,7 +71,7 @@ class WcGatewayModule implements ModuleInterface
|
||||||
|
|
||||||
add_filter(
|
add_filter(
|
||||||
'woocommerce_order_actions',
|
'woocommerce_order_actions',
|
||||||
function ($orderActions): array {
|
static function ($orderActions): array {
|
||||||
$orderActions['ppcp_authorize_order'] = __(
|
$orderActions['ppcp_authorize_order'] = __(
|
||||||
'Capture authorized PayPal payment',
|
'Capture authorized PayPal payment',
|
||||||
'woocommerce-paypal-gateway'
|
'woocommerce-paypal-gateway'
|
||||||
|
@ -82,7 +82,7 @@ class WcGatewayModule implements ModuleInterface
|
||||||
|
|
||||||
add_action(
|
add_action(
|
||||||
'woocommerce_order_action_ppcp_authorize_order',
|
'woocommerce_order_action_ppcp_authorize_order',
|
||||||
function (\WC_Order $wcOrder) use ($container) {
|
static function (\WC_Order $wcOrder) use ($container) {
|
||||||
/**
|
/**
|
||||||
* @var WcGateway $gateway
|
* @var WcGateway $gateway
|
||||||
*/
|
*/
|
||||||
|
@ -93,7 +93,7 @@ class WcGatewayModule implements ModuleInterface
|
||||||
|
|
||||||
add_action(
|
add_action(
|
||||||
'woocommerce_order_actions_start',
|
'woocommerce_order_actions_start',
|
||||||
function ($wcOrderId) use ($container) {
|
static function ($wcOrderId) use ($container) {
|
||||||
/**
|
/**
|
||||||
* @var PaymentStatusOrderDetail $class
|
* @var PaymentStatusOrderDetail $class
|
||||||
*/
|
*/
|
||||||
|
@ -104,7 +104,7 @@ class WcGatewayModule implements ModuleInterface
|
||||||
|
|
||||||
add_filter(
|
add_filter(
|
||||||
'manage_edit-shop_order_columns',
|
'manage_edit-shop_order_columns',
|
||||||
function ($columns) use ($container) {
|
static function ($columns) use ($container) {
|
||||||
/**
|
/**
|
||||||
* @var OrderTablePaymentStatusColumn $paymentStatusColumn
|
* @var OrderTablePaymentStatusColumn $paymentStatusColumn
|
||||||
*/
|
*/
|
||||||
|
@ -115,7 +115,7 @@ class WcGatewayModule implements ModuleInterface
|
||||||
|
|
||||||
add_action(
|
add_action(
|
||||||
'manage_shop_order_posts_custom_column',
|
'manage_shop_order_posts_custom_column',
|
||||||
function ($column, $wcOrderId) use ($container) {
|
static function ($column, $wcOrderId) use ($container) {
|
||||||
/**
|
/**
|
||||||
* @var OrderTablePaymentStatusColumn $paymentStatusColumn
|
* @var OrderTablePaymentStatusColumn $paymentStatusColumn
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue