2020-04-02 08:38:00 +03:00
< ? php
2020-04-16 15:04:53 +03:00
2020-04-02 08:38:00 +03:00
declare ( strict_types = 1 );
namespace Inpsyde\PayPalCommerce\WcGateway ;
use Dhii\Data\Container\ContainerInterface ;
2020-06-15 11:48:37 +03:00
use Inpsyde\PayPalCommerce\Onboarding\State ;
2020-04-23 11:19:09 +03:00
use Inpsyde\PayPalCommerce\WcGateway\Admin\OrderTablePaymentStatusColumn ;
use Inpsyde\PayPalCommerce\WcGateway\Admin\PaymentStatusOrderDetail ;
2020-04-02 08:38:00 +03:00
use Inpsyde\PayPalCommerce\WcGateway\Checkout\DisableGateways ;
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway ;
2020-04-13 22:30:57 +03:00
use Inpsyde\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice ;
2020-04-10 12:36:42 +03:00
use Inpsyde\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice ;
2020-04-16 15:04:53 +03:00
use Inpsyde\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor ;
2020-04-28 13:32:48 +03:00
use Inpsyde\PayPalCommerce\WcGateway\Processor\OrderProcessor ;
2020-04-09 14:02:35 +03:00
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings ;
2020-07-02 09:37:07 +03:00
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsListener ;
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsRenderer ;
2020-04-02 08:38:00 +03:00
return [
2020-04-28 12:31:12 +03:00
'wcgateway.gateway' => static function ( ContainerInterface $container ) : WcGateway {
2020-04-28 13:32:48 +03:00
$orderProcessor = $container -> get ( 'wcgateway.order-processor' );
2020-07-02 09:37:07 +03:00
$settingsRenderer = $container -> get ( 'wcgateway.settings.render' );
2020-04-28 13:32:48 +03:00
$authorizedPayments = $container -> get ( 'wcgateway.processor.authorized-payments' );
2020-04-28 12:31:12 +03:00
$notice = $container -> get ( 'wcgateway.notice.authorize-order-action' );
2020-07-02 14:30:03 +03:00
$settings = $container -> get ( 'wcgateway.settings' );
2020-06-30 08:35:28 +03:00
2020-04-16 15:04:53 +03:00
return new WcGateway (
2020-07-02 09:37:07 +03:00
$settingsRenderer ,
2020-04-28 13:32:48 +03:00
$orderProcessor ,
$authorizedPayments ,
2020-06-15 11:48:37 +03:00
$notice ,
2020-07-02 14:30:03 +03:00
$settings
2020-04-16 15:04:53 +03:00
);
2020-04-02 08:38:00 +03:00
},
2020-04-28 12:31:12 +03:00
'wcgateway.disabler' => static function ( ContainerInterface $container ) : DisableGateways {
2020-04-02 08:38:00 +03:00
$sessionHandler = $container -> get ( 'session.handler' );
2020-07-02 14:37:08 +03:00
$settings = $container -> get ( 'wcgateway.settings' );
return new DisableGateways ( $sessionHandler , $settings );
2020-04-06 11:16:18 +03:00
},
2020-04-28 12:31:12 +03:00
'wcgateway.settings' => static function ( ContainerInterface $container ) : Settings {
2020-07-02 14:30:03 +03:00
return new Settings ();
2020-04-09 14:02:35 +03:00
},
2020-04-28 12:31:12 +03:00
'wcgateway.notice.connect' => static function ( ContainerInterface $container ) : ConnectAdminNotice {
2020-06-15 11:48:37 +03:00
$state = $container -> get ( 'onboarding.state' );
2020-04-10 12:20:08 +03:00
$settings = $container -> get ( 'wcgateway.settings' );
2020-06-15 11:48:37 +03:00
return new ConnectAdminNotice ( $state , $settings );
2020-04-10 12:20:08 +03:00
},
2020-04-13 22:30:57 +03:00
'wcgateway.notice.authorize-order-action' =>
2020-04-28 12:31:12 +03:00
static function ( ContainerInterface $container ) : AuthorizeOrderActionNotice {
2020-04-13 22:30:57 +03:00
return new AuthorizeOrderActionNotice ();
},
2020-07-02 09:37:07 +03:00
'wcgateway.settings.render' => static function ( ContainerInterface $container ) : SettingsRenderer {
$settings = $container -> get ( 'wcgateway.settings' );
2020-06-15 11:48:37 +03:00
$state = $container -> get ( 'onboarding.state' );
2020-07-02 09:37:07 +03:00
$fields = $container -> get ( 'wcgateway.settings.fields' );
return new SettingsRenderer ( $settings , $state , $fields );
},
'wcgateway.settings.listener' => static function ( ContainerInterface $container ) : SettingsListener {
$settings = $container -> get ( 'wcgateway.settings' );
$fields = $container -> get ( 'wcgateway.settings.fields' );
2020-07-08 13:27:48 +03:00
$webhookRegistrar = $container -> get ( 'webhook.registrar' );
2020-07-09 09:10:35 +03:00
global $wpdb ;
$cacheFactory = new CachePoolFactory ( $wpdb );
$pool = $cacheFactory -> createCachePool ( 'ppcp-token' );
return new SettingsListener ( $settings , $fields , $webhookRegistrar , $pool );
2020-04-09 14:36:52 +03:00
},
2020-04-28 13:32:48 +03:00
'wcgateway.order-processor' => static function ( ContainerInterface $container ) : OrderProcessor {
$sessionHandler = $container -> get ( 'session.handler' );
$cartRepository = $container -> get ( 'api.repository.cart' );
$orderEndpoint = $container -> get ( 'api.endpoint.order' );
$paymentsEndpoint = $container -> get ( 'api.endpoint.payments' );
$orderFactory = $container -> get ( 'api.factory.order' );
return new OrderProcessor (
$sessionHandler ,
$cartRepository ,
$orderEndpoint ,
$paymentsEndpoint ,
$orderFactory
);
2020-04-16 15:04:53 +03:00
},
2020-04-28 12:31:12 +03:00
'wcgateway.processor.authorized-payments' => static function ( ContainerInterface $container ) : AuthorizedPaymentsProcessor {
2020-04-16 15:04:53 +03:00
$orderEndpoint = $container -> get ( 'api.endpoint.order' );
$paymentsEndpoint = $container -> get ( 'api.endpoint.payments' );
return new AuthorizedPaymentsProcessor ( $orderEndpoint , $paymentsEndpoint );
},
2020-04-28 12:31:12 +03:00
'wcgateway.admin.order-payment-status' => static function ( ContainerInterface $container ) : PaymentStatusOrderDetail {
2020-04-23 11:19:09 +03:00
return new PaymentStatusOrderDetail ();
2020-04-22 19:27:07 +03:00
},
2020-04-28 12:31:12 +03:00
'wcgateway.admin.orders-payment-status-column' => static function ( ContainerInterface $container ) : OrderTablePaymentStatusColumn {
2020-04-22 19:27:07 +03:00
$settings = $container -> get ( 'wcgateway.settings' );
2020-04-23 11:19:09 +03:00
return new OrderTablePaymentStatusColumn ( $settings );
2020-04-28 12:31:12 +03:00
},
2020-07-02 09:37:07 +03:00
2020-07-02 12:48:40 +03:00
'wcgateway.settings.fields' => static function ( ContainerInterface $container ) : array {
2020-07-02 09:37:07 +03:00
$settings = $container -> get ( 'wcgateway.settings' );
$sandboxText = $settings -> has ( 'sandbox_on' ) && $settings -> get ( 'sandbox_on' ) ?
__ (
'You are currently in the sandbox mode to test your installation. You can switch this, by clicking <button name="%1$s" value="%2$s">Reset</button>' ,
'woocommerce-paypal-commerce-gateway'
) : __ (
'You are in live mode. This means, you can receive money into your account. You can switch this, by clicking <button name="%1$s" value="%2$s">Reset</button>' ,
'woocommerce-paypal-commerce-gateway'
);
$sandboxText = sprintf (
$sandboxText ,
'save' ,
'reset'
);
$merchantEmailText = sprintf (
__ (
' You are connected with your email address < mark >% 1 $s </ mark >.
If you want to change this settings , please click < button name = " %2 $s " value = " %3 $s " > Reset </ button > ' ,
'woocommerce-paypal-commerce-gateway'
),
$settings -> has ( 'merchant_email' ) ? $settings -> get ( 'merchant_email' ) : '' ,
'save' ,
'reset'
);
return [
2020-07-02 13:10:53 +03:00
'ppcp_onboarding' => [
'title' => __ ( 'Connect to PayPal' , 'woocommerce-paypal-gateway' ),
'type' => 'ppcp_onboarding' ,
'screens' => [
State :: STATE_PROGRESSIVE ,
],
],
2020-07-02 09:37:07 +03:00
'sandbox_on' => [
'title' => __ ( 'Sandbox' , 'woocommerce-paypal-gateway' ),
'type' => 'checkbox' ,
'label' => __ ( 'To test your Woocommerce installation, you can use the sandbox mode.' , 'woocommerce-paypal-gateway' ),
'default' => 0 ,
'screens' => [
State :: STATE_START ,
],
],
'sandbox_on_info' => [
'title' => __ ( 'Sandbox' , 'woocommerce-paypal-gateway' ),
'type' => 'ppcp-text' ,
'text' => $sandboxText ,
'screens' => [
State :: STATE_PROGRESSIVE ,
State :: STATE_ONBOARDED ,
],
'hidden' => 'sandbox_on' ,
],
'merchant_email' => [
'title' => __ ( 'Email address' , 'woocommerce-paypal-gateway' ),
'type' => 'text' ,
2020-07-08 13:27:48 +03:00
'desc_tip' => true ,
'description' => __ ( 'The email address of your PayPal account.' , 'woocommerce-paypal-gateway' ),
2020-07-02 09:37:07 +03:00
'default' => '' ,
'screens' => [
State :: STATE_START ,
],
],
'merchant_email_info' => [
'title' => __ ( 'Email address' , 'woocommerce-paypal-gateway' ),
'type' => 'ppcp-text' ,
'text' => $merchantEmailText ,
'screens' => [
State :: STATE_PROGRESSIVE ,
State :: STATE_ONBOARDED ,
],
'hidden' => 'merchant_email' ,
],
'title' => [
'title' => __ ( 'Title' , 'woocommerce-paypal-gateway' ),
'type' => 'text' ,
'description' => __ (
'This controls the title which the user sees during checkout.' ,
'woocommerce-paypal-gateway'
),
'default' => __ ( 'PayPal' , 'woocommerce-paypal-gateway' ),
'desc_tip' => true ,
'screens' => [
State :: STATE_PROGRESSIVE ,
State :: STATE_ONBOARDED ,
],
],
'description' => [
'title' => __ ( 'Description' , 'woocommerce-paypal-gateway' ),
'type' => 'text' ,
'desc_tip' => true ,
'description' => __ (
'This controls the description which the user sees during checkout.' ,
'woocommerce-paypal-gateway'
),
'default' => __ (
'Pay via PayPal; you can pay with your credit card if you don\'t have a PayPal account.' ,
'woocommerce-paypal-gateway'
),
'screens' => [
State :: STATE_PROGRESSIVE ,
State :: STATE_ONBOARDED ,
],
],
2020-07-08 13:27:48 +03:00
'intent' => [
'title' => __ ( 'Intent' , 'woocommerce-paypal-gateway' ),
'type' => 'select' ,
'class' => [ 'wc-enhanced-select' ],
'default' => 'capture' ,
'desc_tip' => true ,
'description' => __ (
'The intent to either capture payment immediately or authorize a payment for an order after order creation.' ,
'woocommerce-paypal-gateway'
),
'options' => [
'capture' => __ ( 'Capture' , 'woocommerce-paypal-gateway' ),
'authorize' => __ ( 'Authorize' , 'woocommerce-paypal-gateway' ),
],
'screens' => [
State :: STATE_ONBOARDED ,
],
],
2020-07-02 09:37:07 +03:00
'button_single_product_enabled' => [
'title' => __ ( 'Buttons on Single Product' , 'woocommerce-paypal-gateway' ),
'type' => 'checkbox' ,
'label' => __ ( 'Enable on Single Product' , 'woocommerce-paypal-gateway' ),
'default' => 1 ,
'screens' => [
State :: STATE_PROGRESSIVE ,
State :: STATE_ONBOARDED ,
],
],
'button_mini_cart_enabled' => [
'title' => __ ( 'Buttons on Mini Cart' , 'woocommerce-paypal-gateway' ),
'type' => 'checkbox' ,
'label' => __ ( 'Enable on Mini Cart' , 'woocommerce-paypal-gateway' ),
'default' => 1 ,
'screens' => [
State :: STATE_PROGRESSIVE ,
State :: STATE_ONBOARDED ,
],
],
'button_cart_enabled' => [
'title' => __ ( 'Buttons on Cart' , 'woocommerce-paypal-gateway' ),
'type' => 'checkbox' ,
'label' => __ ( 'Enable on Cart' , 'woocommerce-paypal-gateway' ),
'default' => 1 ,
'screens' => [
State :: STATE_PROGRESSIVE ,
State :: STATE_ONBOARDED ,
],
],
'button_color' => [
'title' => __ ( 'Color' , 'woocommerce-paypal-gateway' ),
'type' => 'select' ,
'class' => [ 'wc-enhanced-select' ],
'default' => 'gold' ,
'desc_tip' => true ,
'description' => __ (
'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.' ,
'woocommerce-paypal-gateway'
),
'options' => [
'gold' => __ ( 'Gold (Recommended)' , 'woocommerce-paypal-gateway' ),
'blue' => __ ( 'Blue' , 'woocommerce-paypal-gateway' ),
'silver' => __ ( 'Silver' , 'woocommerce-paypal-gateway' ),
'black' => __ ( 'Black' , 'woocommerce-paypal-gateway' ),
],
'screens' => [
State :: STATE_PROGRESSIVE ,
State :: STATE_ONBOARDED ,
],
],
'button_shape' => [
'title' => __ ( 'Shape' , 'woocommerce-paypal-gateway' ),
'type' => 'select' ,
'class' => [ 'wc-enhanced-select' ],
'default' => 'rect' ,
'desc_tip' => true ,
'description' => __ (
'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.' ,
'woocommerce-paypal-gateway'
),
'options' => [
'pill' => __ ( 'Pill' , 'woocommerce-paypal-gateway' ),
'rect' => __ ( 'Rectangle' , 'woocommerce-paypal-gateway' ),
],
'screens' => [
State :: STATE_PROGRESSIVE ,
State :: STATE_ONBOARDED ,
],
],
'disable_funding' => [
'title' => __ ( 'Disable funding sources' , 'woocommerce-paypal-gateway' ),
'type' => 'ppcp-multiselect' ,
'class' => [ 'wc-enhanced-select' ],
'default' => [],
'desc_tip' => true ,
'description' => __ (
'By default all possible funding sources will be shown. You can disable some sources, if you wish.' ,
'woocommerce-paypal-gateway'
),
'options' => [
'card' => _x ( 'Credit or debit cards' , 'Name of payment method' , 'woocommerce-paypal-gateway' ),
'credit' => _x ( 'PayPal Credit' , 'Name of payment method' , 'woocommerce-paypal-gateway' ),
'venmo' => _x ( 'Venmo' , 'Name of payment method' , 'woocommerce-paypal-gateway' ),
'sepa' => _x ( 'SEPA-Lastschrift' , 'Name of payment method' , 'woocommerce-paypal-gateway' ),
'bancontact' => _x ( 'Bancontact' , 'Name of payment method' , 'woocommerce-paypal-gateway' ),
'eps' => _x ( 'eps' , 'Name of payment method' , 'woocommerce-paypal-gateway' ),
'giropay' => _x ( 'giropay' , 'Name of payment method' , 'woocommerce-paypal-gateway' ),
'ideal' => _x ( 'iDEAL' , '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' ),
'sofort' => _x ( 'Sofort' , 'Name of payment method' , 'woocommerce-paypal-gateway' ),
],
'screens' => [
State :: STATE_PROGRESSIVE ,
State :: STATE_ONBOARDED ,
],
],
'dcc_cart_enabled' => [
'title' => __ ( 'Enable credit card on cart' , 'woocommerce-paypal-gateway' ),
'type' => 'checkbox' ,
'label' => __ ( 'Allow your customers to pay with credit card directly in your cart.' , 'woocommerce-paypal-gateway' ),
'default' => 1 ,
'screens' => [
State :: STATE_ONBOARDED ,
],
],
'dcc_mini_cart_enabled' => [
'title' => __ ( 'Enable credit card on mini cart' , 'woocommerce-paypal-gateway' ),
'type' => 'checkbox' ,
'label' => __ ( 'Allow your customers to pay with credit card directly in your mini cart.' , 'woocommerce-paypal-gateway' ),
'default' => 1 ,
'screens' => [
State :: STATE_ONBOARDED ,
],
],
'dcc_checkout_enabled' => [
'title' => __ ( 'Enable credit card on checkout' , 'woocommerce-paypal-gateway' ),
'type' => 'checkbox' ,
'label' => __ ( 'Allow your customers to pay with credit card in the checkout.' , 'woocommerce-paypal-gateway' ),
'default' => 1 ,
'screens' => [
State :: STATE_ONBOARDED ,
],
],
'dcc_single_product_enabled' => [
'title' => __ ( 'Enable credit card on products' , 'woocommerce-paypal-gateway' ),
'type' => 'checkbox' ,
'label' => __ ( 'Allow your customers to pay with credit card instantly on the product page.' , 'woocommerce-paypal-gateway' ),
'default' => 1 ,
'screens' => [
State :: STATE_ONBOARDED ,
],
],
'disable_cards' => [
'title' => __ ( 'Disable specific credid cards' , 'woocommerce-paypal-gateway' ),
'type' => 'ppcp-multiselect' ,
'class' => [ 'wc-enhanced-select' ],
'default' => [],
'desc_tip' => true ,
'description' => __ (
'By default all possible credit cards will be shown. You can disable some cards, if you wish.' ,
'woocommerce-paypal-gateway'
),
'options' => [
'visa' => _x ( 'Visa' , 'Name of credit card' , 'woocommerce-paypal-gateway' ),
'mastercard' => _x ( 'Mastercard' , 'Name of credit card' , 'woocommerce-paypal-gateway' ),
'amex' => _x ( 'American Express' , 'Name of credit card' , 'woocommerce-paypal-gateway' ),
'discover' => _x ( 'Discover' , 'Name of credit card' , 'woocommerce-paypal-gateway' ),
'jcb' => _x ( 'JCB' , 'Name of credit card' , 'woocommerce-paypal-gateway' ),
'elo' => _x ( 'Elo' , 'Name of credit card' , 'woocommerce-paypal-gateway' ),
'hiper' => _x ( 'Hiper' , 'Name of credit card' , 'woocommerce-paypal-gateway' ),
],
'screens' => [
State :: STATE_ONBOARDED ,
],
],
];
2020-07-02 12:48:40 +03:00
},
2020-04-02 08:38:00 +03:00
];