mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Add pui payment source entity (WIP)
This commit is contained in:
parent
753b8bae3e
commit
da3272e687
8 changed files with 250 additions and 119 deletions
|
@ -32,6 +32,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
|||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNet;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\FraudNetSessionId;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\OrderEndpoint;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PaymentSourceFactory;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoice;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
|
||||
|
@ -50,7 +51,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
|
|||
use WooCommerce\PayPalCommerce\Webhooks\Status\WebhooksStatusPage;
|
||||
|
||||
return array(
|
||||
'wcgateway.paypal-gateway' => static function ( ContainerInterface $container ): PayPalGateway {
|
||||
'wcgateway.paypal-gateway' => static function ( ContainerInterface $container ): PayPalGateway {
|
||||
$order_processor = $container->get( 'wcgateway.order-processor' );
|
||||
$settings_renderer = $container->get( 'wcgateway.settings.render' );
|
||||
$funding_source_renderer = $container->get( 'wcgateway.funding-source.renderer' );
|
||||
|
@ -86,7 +87,7 @@ return array(
|
|||
$order_endpoint
|
||||
);
|
||||
},
|
||||
'wcgateway.credit-card-gateway' => static function ( ContainerInterface $container ): CreditCardGateway {
|
||||
'wcgateway.credit-card-gateway' => static function ( ContainerInterface $container ): CreditCardGateway {
|
||||
$order_processor = $container->get( 'wcgateway.order-processor' );
|
||||
$settings_renderer = $container->get( 'wcgateway.settings.render' );
|
||||
$authorized_payments = $container->get( 'wcgateway.processor.authorized-payments' );
|
||||
|
@ -124,18 +125,18 @@ return array(
|
|||
$payments_endpoint
|
||||
);
|
||||
},
|
||||
'wcgateway.disabler' => static function ( ContainerInterface $container ): DisableGateways {
|
||||
'wcgateway.disabler' => static function ( ContainerInterface $container ): DisableGateways {
|
||||
$session_handler = $container->get( 'session.handler' );
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
return new DisableGateways( $session_handler, $settings );
|
||||
},
|
||||
'wcgateway.is-wc-payments-page' => static function ( ContainerInterface $container ): bool {
|
||||
'wcgateway.is-wc-payments-page' => static function ( ContainerInterface $container ): bool {
|
||||
$page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
|
||||
$tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : '';
|
||||
return 'wc-settings' === $page && 'checkout' === $tab;
|
||||
},
|
||||
|
||||
'wcgateway.is-ppcp-settings-page' => static function ( ContainerInterface $container ): bool {
|
||||
'wcgateway.is-ppcp-settings-page' => static function ( ContainerInterface $container ): bool {
|
||||
if ( ! $container->get( 'wcgateway.is-wc-payments-page' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -144,7 +145,7 @@ return array(
|
|||
return in_array( $section, array( PayPalGateway::ID, CreditCardGateway::ID, WebhooksStatusPage::ID ), true );
|
||||
},
|
||||
|
||||
'wcgateway.current-ppcp-settings-page-id' => static function ( ContainerInterface $container ): string {
|
||||
'wcgateway.current-ppcp-settings-page-id' => static function ( ContainerInterface $container ): string {
|
||||
if ( ! $container->get( 'wcgateway.is-ppcp-settings-page' ) ) {
|
||||
return '';
|
||||
}
|
||||
|
@ -155,33 +156,33 @@ return array(
|
|||
return $ppcp_tab ? $ppcp_tab : $section;
|
||||
},
|
||||
|
||||
'wcgateway.settings' => static function ( ContainerInterface $container ): Settings {
|
||||
'wcgateway.settings' => static function ( ContainerInterface $container ): Settings {
|
||||
return new Settings();
|
||||
},
|
||||
'wcgateway.notice.connect' => static function ( ContainerInterface $container ): ConnectAdminNotice {
|
||||
'wcgateway.notice.connect' => static function ( ContainerInterface $container ): ConnectAdminNotice {
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
return new ConnectAdminNotice( $state, $settings );
|
||||
},
|
||||
'wcgateway.notice.dcc-without-paypal' => static function ( ContainerInterface $container ): DccWithoutPayPalAdminNotice {
|
||||
'wcgateway.notice.dcc-without-paypal' => static function ( ContainerInterface $container ): DccWithoutPayPalAdminNotice {
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
$is_payments_page = $container->get( 'wcgateway.is-wc-payments-page' );
|
||||
$is_ppcp_settings_page = $container->get( 'wcgateway.is-ppcp-settings-page' );
|
||||
return new DccWithoutPayPalAdminNotice( $state, $settings, $is_payments_page, $is_ppcp_settings_page );
|
||||
},
|
||||
'wcgateway.notice.authorize-order-action' =>
|
||||
'wcgateway.notice.authorize-order-action' =>
|
||||
static function ( ContainerInterface $container ): AuthorizeOrderActionNotice {
|
||||
return new AuthorizeOrderActionNotice();
|
||||
},
|
||||
'wcgateway.settings.sections-renderer' => static function ( ContainerInterface $container ): SectionsRenderer {
|
||||
'wcgateway.settings.sections-renderer' => static function ( ContainerInterface $container ): SectionsRenderer {
|
||||
return new SectionsRenderer( $container->get( 'wcgateway.current-ppcp-settings-page-id' ) );
|
||||
},
|
||||
'wcgateway.settings.status' => static function ( ContainerInterface $container ): SettingsStatus {
|
||||
'wcgateway.settings.status' => static function ( ContainerInterface $container ): SettingsStatus {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
return new SettingsStatus( $settings );
|
||||
},
|
||||
'wcgateway.settings.render' => static function ( ContainerInterface $container ): SettingsRenderer {
|
||||
'wcgateway.settings.render' => static function ( ContainerInterface $container ): SettingsRenderer {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
$fields = $container->get( 'wcgateway.settings.fields' );
|
||||
|
@ -201,7 +202,7 @@ return array(
|
|||
$page_id
|
||||
);
|
||||
},
|
||||
'wcgateway.settings.listener' => static function ( ContainerInterface $container ): SettingsListener {
|
||||
'wcgateway.settings.listener' => static function ( ContainerInterface $container ): SettingsListener {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
$fields = $container->get( 'wcgateway.settings.fields' );
|
||||
$webhook_registrar = $container->get( 'webhook.registrar' );
|
||||
|
@ -211,7 +212,7 @@ return array(
|
|||
$page_id = $container->get( 'wcgateway.current-ppcp-settings-page-id' );
|
||||
return new SettingsListener( $settings, $fields, $webhook_registrar, $cache, $state, $bearer, $page_id );
|
||||
},
|
||||
'wcgateway.order-processor' => static function ( ContainerInterface $container ): OrderProcessor {
|
||||
'wcgateway.order-processor' => static function ( ContainerInterface $container ): OrderProcessor {
|
||||
|
||||
$session_handler = $container->get( 'session.handler' );
|
||||
$order_endpoint = $container->get( 'api.endpoint.order' );
|
||||
|
@ -232,36 +233,36 @@ return array(
|
|||
$environment
|
||||
);
|
||||
},
|
||||
'wcgateway.processor.refunds' => static function ( ContainerInterface $container ): RefundProcessor {
|
||||
'wcgateway.processor.refunds' => static function ( ContainerInterface $container ): RefundProcessor {
|
||||
$order_endpoint = $container->get( 'api.endpoint.order' );
|
||||
$payments_endpoint = $container->get( 'api.endpoint.payments' );
|
||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||
return new RefundProcessor( $order_endpoint, $payments_endpoint, $logger );
|
||||
},
|
||||
'wcgateway.processor.authorized-payments' => static function ( ContainerInterface $container ): AuthorizedPaymentsProcessor {
|
||||
'wcgateway.processor.authorized-payments' => static function ( ContainerInterface $container ): AuthorizedPaymentsProcessor {
|
||||
$order_endpoint = $container->get( 'api.endpoint.order' );
|
||||
$payments_endpoint = $container->get( 'api.endpoint.payments' );
|
||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||
$notice = $container->get( 'wcgateway.notice.authorize-order-action' );
|
||||
return new AuthorizedPaymentsProcessor( $order_endpoint, $payments_endpoint, $logger, $notice );
|
||||
},
|
||||
'wcgateway.admin.render-authorize-action' => static function ( ContainerInterface $container ): RenderAuthorizeAction {
|
||||
'wcgateway.admin.render-authorize-action' => static function ( ContainerInterface $container ): RenderAuthorizeAction {
|
||||
$column = $container->get( 'wcgateway.admin.orders-payment-status-column' );
|
||||
return new RenderAuthorizeAction( $column );
|
||||
},
|
||||
'wcgateway.admin.order-payment-status' => static function ( ContainerInterface $container ): PaymentStatusOrderDetail {
|
||||
'wcgateway.admin.order-payment-status' => static function ( ContainerInterface $container ): PaymentStatusOrderDetail {
|
||||
$column = $container->get( 'wcgateway.admin.orders-payment-status-column' );
|
||||
return new PaymentStatusOrderDetail( $column );
|
||||
},
|
||||
'wcgateway.admin.orders-payment-status-column' => static function ( ContainerInterface $container ): OrderTablePaymentStatusColumn {
|
||||
'wcgateway.admin.orders-payment-status-column' => static function ( ContainerInterface $container ): OrderTablePaymentStatusColumn {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
return new OrderTablePaymentStatusColumn( $settings );
|
||||
},
|
||||
'wcgateway.admin.fees-renderer' => static function ( ContainerInterface $container ): FeesRenderer {
|
||||
'wcgateway.admin.fees-renderer' => static function ( ContainerInterface $container ): FeesRenderer {
|
||||
return new FeesRenderer();
|
||||
},
|
||||
|
||||
'wcgateway.settings.fields' => static function ( ContainerInterface $container ): array {
|
||||
'wcgateway.settings.fields' => static function ( ContainerInterface $container ): array {
|
||||
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
assert( $state instanceof State );
|
||||
|
@ -2058,28 +2059,28 @@ return array(
|
|||
return $fields;
|
||||
},
|
||||
|
||||
'wcgateway.checkout.address-preset' => static function( ContainerInterface $container ): CheckoutPayPalAddressPreset {
|
||||
'wcgateway.checkout.address-preset' => static function( ContainerInterface $container ): CheckoutPayPalAddressPreset {
|
||||
|
||||
return new CheckoutPayPalAddressPreset(
|
||||
$container->get( 'session.handler' )
|
||||
);
|
||||
},
|
||||
'wcgateway.url' => static function ( ContainerInterface $container ): string {
|
||||
'wcgateway.url' => static function ( ContainerInterface $container ): string {
|
||||
return plugins_url(
|
||||
$container->get( 'wcgateway.relative-path' ),
|
||||
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
|
||||
);
|
||||
},
|
||||
'wcgateway.relative-path' => static function( ContainerInterface $container ): string {
|
||||
'wcgateway.relative-path' => static function( ContainerInterface $container ): string {
|
||||
return 'modules/ppcp-wc-gateway/';
|
||||
},
|
||||
'wcgateway.absolute-path' => static function( ContainerInterface $container ): string {
|
||||
'wcgateway.absolute-path' => static function( ContainerInterface $container ): string {
|
||||
return plugin_dir_path(
|
||||
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
|
||||
) .
|
||||
$container->get( 'wcgateway.relative-path' );
|
||||
},
|
||||
'wcgateway.endpoint.return-url' => static function ( ContainerInterface $container ) : ReturnUrlEndpoint {
|
||||
'wcgateway.endpoint.return-url' => static function ( ContainerInterface $container ) : ReturnUrlEndpoint {
|
||||
$gateway = $container->get( 'wcgateway.paypal-gateway' );
|
||||
$endpoint = $container->get( 'api.endpoint.order' );
|
||||
$prefix = $container->get( 'api.prefix' );
|
||||
|
@ -2090,69 +2091,73 @@ return array(
|
|||
);
|
||||
},
|
||||
|
||||
'wcgateway.transaction-url-sandbox' => static function ( ContainerInterface $container ): string {
|
||||
'wcgateway.transaction-url-sandbox' => static function ( ContainerInterface $container ): string {
|
||||
return 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%s';
|
||||
},
|
||||
|
||||
'wcgateway.transaction-url-live' => static function ( ContainerInterface $container ): string {
|
||||
'wcgateway.transaction-url-live' => static function ( ContainerInterface $container ): string {
|
||||
return 'https://www.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%s';
|
||||
},
|
||||
|
||||
'wcgateway.transaction-url-provider' => static function ( ContainerInterface $container ): TransactionUrlProvider {
|
||||
'wcgateway.transaction-url-provider' => static function ( ContainerInterface $container ): TransactionUrlProvider {
|
||||
$sandbox_url_base = $container->get( 'wcgateway.transaction-url-sandbox' );
|
||||
$live_url_base = $container->get( 'wcgateway.transaction-url-live' );
|
||||
|
||||
return new TransactionUrlProvider( $sandbox_url_base, $live_url_base );
|
||||
},
|
||||
|
||||
'wcgateway.helper.dcc-product-status' => static function ( ContainerInterface $container ) : DCCProductStatus {
|
||||
'wcgateway.helper.dcc-product-status' => static function ( ContainerInterface $container ) : DCCProductStatus {
|
||||
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
$partner_endpoint = $container->get( 'api.endpoint.partners' );
|
||||
return new DCCProductStatus( $settings, $partner_endpoint );
|
||||
},
|
||||
|
||||
'button.helper.messages-disclaimers' => static function ( ContainerInterface $container ): MessagesDisclaimers {
|
||||
'button.helper.messages-disclaimers' => static function ( ContainerInterface $container ): MessagesDisclaimers {
|
||||
return new MessagesDisclaimers(
|
||||
$container->get( 'api.shop.country' )
|
||||
);
|
||||
},
|
||||
|
||||
'wcgateway.funding-source.renderer' => function ( ContainerInterface $container ) : FundingSourceRenderer {
|
||||
'wcgateway.funding-source.renderer' => function ( ContainerInterface $container ) : FundingSourceRenderer {
|
||||
return new FundingSourceRenderer(
|
||||
$container->get( 'wcgateway.settings' )
|
||||
);
|
||||
},
|
||||
'wcgateway.pay-upon-invoice-order-endpoint' => static function (ContainerInterface $container): OrderEndpoint {
|
||||
'wcgateway.pay-upon-invoice-order-endpoint' => static function ( ContainerInterface $container ): OrderEndpoint {
|
||||
return new OrderEndpoint(
|
||||
$container->get( 'api.host' ),
|
||||
$container->get( 'api.bearer' ),
|
||||
$container->get( 'api.factory.order' ),
|
||||
$container->get('wcgateway.pay-upon-invoice-fraudnet'),
|
||||
$container->get( 'wcgateway.pay-upon-invoice-fraudnet' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' )
|
||||
);
|
||||
},
|
||||
'wcgateway.pay-upon-invoice-gateway' => static function (ContainerInterface $container): PayUponInvoiceGateway {
|
||||
'wcgateway.pay-upon-invoice-payment-source-factory' => static function ( ContainerInterface $container ): PaymentSourceFactory {
|
||||
return new PaymentSourceFactory();
|
||||
},
|
||||
'wcgateway.pay-upon-invoice-gateway' => static function ( ContainerInterface $container ): PayUponInvoiceGateway {
|
||||
return new PayUponInvoiceGateway(
|
||||
$container->get( 'wcgateway.pay-upon-invoice-order-endpoint' ),
|
||||
$container->get( 'api.factory.purchase-unit' ),
|
||||
$container->get( 'wcgateway.pay-upon-invoice-payment-source-factory' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' )
|
||||
);
|
||||
},
|
||||
'wcgateway.pay-upon-invoice-fraudnet-session-id' => static function (ContainerInterface $container): FraudNetSessionId {
|
||||
'wcgateway.pay-upon-invoice-fraudnet-session-id' => static function ( ContainerInterface $container ): FraudNetSessionId {
|
||||
return new FraudNetSessionId();
|
||||
},
|
||||
'wcgateway.pay-upon-invoice-fraudnet' => static function (ContainerInterface $container): FraudNet {
|
||||
$session_id = $container->get('wcgateway.pay-upon-invoice-fraudnet-session-id');
|
||||
'wcgateway.pay-upon-invoice-fraudnet' => static function ( ContainerInterface $container ): FraudNet {
|
||||
$session_id = $container->get( 'wcgateway.pay-upon-invoice-fraudnet-session-id' );
|
||||
return new FraudNet(
|
||||
(string)$session_id(),
|
||||
(string) $session_id(),
|
||||
'bar'
|
||||
);
|
||||
},
|
||||
'wcgateway.pay-upon-invoice' => static function (ContainerInterface $container): PayUponInvoice {
|
||||
'wcgateway.pay-upon-invoice' => static function ( ContainerInterface $container ): PayUponInvoice {
|
||||
return new PayUponInvoice(
|
||||
$container->get('wcgateway.url'),
|
||||
$container->get('wcgateway.pay-upon-invoice-fraudnet')
|
||||
$container->get( 'wcgateway.url' ),
|
||||
$container->get( 'wcgateway.pay-upon-invoice-fraudnet' )
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
|
||||
|
||||
class FraudNet
|
||||
{
|
||||
class FraudNet {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -14,25 +14,22 @@ class FraudNet
|
|||
*/
|
||||
protected $source_website_id;
|
||||
|
||||
public function __construct(string $session_id, string $source_website_id)
|
||||
{
|
||||
$this->session_id = $session_id;
|
||||
public function __construct( string $session_id, string $source_website_id ) {
|
||||
$this->session_id = $session_id;
|
||||
$this->source_website_id = $source_website_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function sessionId(): string
|
||||
{
|
||||
public function sessionId(): string {
|
||||
return $this->session_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function sourceWebsiteId(): string
|
||||
{
|
||||
public function sourceWebsiteId(): string {
|
||||
return $this->source_website_id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,17 +2,16 @@
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
|
||||
|
||||
class FraudNetSessionId
|
||||
{
|
||||
public function __invoke()
|
||||
{
|
||||
if(WC()->session->get( 'ppcp_fraudnet_session_id' )) {
|
||||
class FraudNetSessionId {
|
||||
|
||||
public function __invoke() {
|
||||
if ( WC()->session->get( 'ppcp_fraudnet_session_id' ) ) {
|
||||
return WC()->session->get( 'ppcp_fraudnet_session_id' );
|
||||
}
|
||||
|
||||
$session_id = bin2hex(random_bytes(16));
|
||||
WC()->session->set( 'ppcp_fraudnet_session_id', $session_id);
|
||||
$session_id = bin2hex( random_bytes( 16 ) );
|
||||
WC()->session->set( 'ppcp_fraudnet_session_id', $session_id );
|
||||
|
||||
return bin2hex($session_id);
|
||||
return $session_id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,15 +32,16 @@ class OrderEndpoint {
|
|||
*/
|
||||
protected $order_factory;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
/**
|
||||
* @var FraudNet
|
||||
*/
|
||||
protected $fraudNet;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
public function __construct(
|
||||
string $host,
|
||||
Bearer $bearer,
|
||||
|
@ -52,7 +53,7 @@ class OrderEndpoint {
|
|||
$this->bearer = $bearer;
|
||||
$this->order_factory = $order_factory;
|
||||
$this->logger = $logger;
|
||||
$this->fraudNet = $fraudNet;
|
||||
$this->fraudNet = $fraudNet;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,7 +62,7 @@ class OrderEndpoint {
|
|||
* @param PurchaseUnit[] $items The purchase unit items for the order.
|
||||
* @return Order
|
||||
*/
|
||||
public function create( array $items ): Order {
|
||||
public function create( array $items, PaymentSource $payment_source ): Order {
|
||||
$data = array(
|
||||
'intent' => 'CAPTURE',
|
||||
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
|
||||
|
@ -72,32 +73,7 @@ class OrderEndpoint {
|
|||
$items
|
||||
),
|
||||
'payment_source' => array(
|
||||
'pay_upon_invoice' => array(
|
||||
'name' => array(
|
||||
'given_name' => 'John',
|
||||
'surname' => 'Doe',
|
||||
),
|
||||
'email' => 'buyer@example.com',
|
||||
'birth_date' => '1990-01-01',
|
||||
'phone' => array(
|
||||
'national_number' => '6912345678',
|
||||
'country_code' => '49',
|
||||
),
|
||||
'billing_address' => array(
|
||||
'address_line_1' => 'Schönhauser Allee 84',
|
||||
'admin_area_2' => 'Berlin',
|
||||
'postal_code' => '10439',
|
||||
'country_code' => 'DE',
|
||||
),
|
||||
'experience_context' => array(
|
||||
'locale' => 'en-DE',
|
||||
'brand_name' => 'EXAMPLE INC',
|
||||
'logo_url' => 'https://example.com/logoUrl.svg',
|
||||
'customer_service_instructions' => array(
|
||||
'Customer service phone is +49 6912345678.',
|
||||
),
|
||||
),
|
||||
),
|
||||
'pay_upon_invoice' => $payment_source->to_array(),
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -28,6 +28,11 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
*/
|
||||
protected $purchase_unit_factory;
|
||||
|
||||
/**
|
||||
* @var PaymentSourceFactory
|
||||
*/
|
||||
protected $payment_source_factory;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
|
@ -36,15 +41,15 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
public function __construct(
|
||||
OrderEndpoint $order_endpoint,
|
||||
PurchaseUnitFactory $purchase_unit_factory,
|
||||
PaymentSourceFactory $payment_source_factory,
|
||||
LoggerInterface $logger
|
||||
)
|
||||
{
|
||||
$this->id = self::ID;
|
||||
) {
|
||||
$this->id = self::ID;
|
||||
|
||||
$this->method_title = __('Pay Upon Invoice', 'woocommerce-paypal-payments');
|
||||
$this->method_description = __('Once you place an order, pay within 30 days. Our payment partner Ratepay will send you payment instructions.', 'woocommerce-paypal-payments');
|
||||
$this->title = $this->method_title;
|
||||
$this->description = $this->method_description;
|
||||
$this->method_title = __( 'Pay Upon Invoice', 'woocommerce-paypal-payments' );
|
||||
$this->method_description = __( 'Once you place an order, pay within 30 days. Our payment partner Ratepay will send you payment instructions.', 'woocommerce-paypal-payments' );
|
||||
$this->title = $this->method_title;
|
||||
$this->description = $this->method_description;
|
||||
|
||||
$this->init_form_fields();
|
||||
$this->init_settings();
|
||||
|
@ -57,9 +62,10 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
)
|
||||
);
|
||||
|
||||
$this->order_endpoint = $order_endpoint;
|
||||
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||
$this->logger = $logger;
|
||||
$this->order_endpoint = $order_endpoint;
|
||||
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||
$this->payment_source_factory = $payment_source_factory;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,33 +73,33 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
*/
|
||||
public function init_form_fields() {
|
||||
$this->form_fields = array(
|
||||
'enabled' => array(
|
||||
'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'label' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
|
||||
'default' => 'yes'
|
||||
'enabled' => array(
|
||||
'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'label' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
|
||||
'default' => 'yes',
|
||||
),
|
||||
'legal_text' => array(
|
||||
'title' => __( 'Legal text', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'textarea',
|
||||
'title' => __( 'Legal text', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'textarea',
|
||||
'default' => 'By clicking on the button, you agree to the <a href="https://www.ratepay.com/legal-payment-terms">terms of payment</a> and <a href="https://www.ratepay.com/legal-payment-dataprivacy">performance of a risk check</a> from the payment partner, Ratepay. You also agree to PayPal’s <a href="https://www.paypal.com/de/webapps/mpp/ua/privacy-full?locale.x=eng_DE&_ga=1.267010504.718583817.1563460395">privacy statement</a>. If your request to purchase upon invoice is accepted, the purchase price claim will be assigned to Ratepay, and you may only pay Ratepay, not the merchant.',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function process_payment($order_id)
|
||||
{
|
||||
public function process_payment( $order_id ) {
|
||||
$wc_order = wc_get_order( $order_id );
|
||||
$wc_order->update_status('on-hold', __('Awaiting Pay Upon Invoice payment', 'woocommerce-paypal-payments'));
|
||||
$wc_order->update_status( 'on-hold', __( 'Awaiting Pay Upon Invoice payment', 'woocommerce-paypal-payments' ) );
|
||||
|
||||
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
|
||||
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
|
||||
$payment_source = $this->payment_source_factory->from_wc_order( $wc_order );
|
||||
|
||||
try {
|
||||
$this->order_endpoint->create(array( $purchase_unit ));
|
||||
} catch (RuntimeException $exception) {
|
||||
$this->order_endpoint->create( array( $purchase_unit ), $payment_source );
|
||||
} catch ( RuntimeException $exception ) {
|
||||
$error = $exception->getMessage();
|
||||
|
||||
$this->logger->error($error);
|
||||
$this->logger->error( $error );
|
||||
wc_add_notice( $error, 'error' );
|
||||
|
||||
$wc_order->update_status(
|
||||
|
|
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
|
||||
|
||||
class PaymentSource {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $given_name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $surname;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $email;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $birth_date;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $national_number;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $phone_country_code;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $address_line_1;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $admin_area_2;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $postal_code;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $country_code;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $locale;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $brand_name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $logo_url;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $customer_service_instructions;
|
||||
|
||||
public function __construct(
|
||||
string $given_name,
|
||||
string $surname,
|
||||
string $email,
|
||||
string $birth_date,
|
||||
string $national_number,
|
||||
string $phone_country_code,
|
||||
string $address_line_1,
|
||||
string $admin_area_2,
|
||||
string $postal_code,
|
||||
string $country_code,
|
||||
string $locale,
|
||||
string $brand_name,
|
||||
string $logo_url,
|
||||
array $customer_service_instructions
|
||||
) {
|
||||
$this->given_name = $given_name;
|
||||
$this->surname = $surname;
|
||||
$this->email = $email;
|
||||
$this->birth_date = $birth_date;
|
||||
$this->national_number = $national_number;
|
||||
$this->phone_country_code = $phone_country_code;
|
||||
$this->address_line_1 = $address_line_1;
|
||||
$this->admin_area_2 = $admin_area_2;
|
||||
$this->postal_code = $postal_code;
|
||||
$this->country_code = $country_code;
|
||||
$this->locale = $locale;
|
||||
$this->brand_name = $brand_name;
|
||||
$this->logo_url = $logo_url;
|
||||
$this->customer_service_instructions = $customer_service_instructions;
|
||||
}
|
||||
|
||||
public function to_array(): array {
|
||||
return array(
|
||||
'name' => array(
|
||||
'given_name' => $this->given_name,
|
||||
'surname' => $this->surname,
|
||||
),
|
||||
'email' => $this->email,
|
||||
'birth_date' => $this->birth_date,
|
||||
'phone' => array(
|
||||
'national_number' => $this->national_number,
|
||||
'country_code' => $this->phone_country_code,
|
||||
),
|
||||
'billing_address' => array(
|
||||
'address_line_1' => $this->address_line_1,
|
||||
'admin_area_2' => $this->admin_area_2,
|
||||
'postal_code' => $this->postal_code,
|
||||
'country_code' => $this->country_code,
|
||||
),
|
||||
'experience_context' => array(
|
||||
'locale' => $this->locale,
|
||||
'brand_name' => $this->brand_name,
|
||||
'logo_url' => $this->logo_url,
|
||||
'customer_service_instructions' => $this->customer_service_instructions,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice;
|
||||
|
||||
use WC_Order;
|
||||
|
||||
class PaymentSourceFactory {
|
||||
|
||||
public function from_wc_order( WC_Order $order ) {
|
||||
|
||||
return new PaymentSource();
|
||||
}
|
||||
}
|
|
@ -185,9 +185,9 @@ class WCGatewayModule implements ModuleInterface {
|
|||
|
||||
add_action(
|
||||
'init',
|
||||
function () use ($c) {
|
||||
function () use ( $c ) {
|
||||
if ( 'DE' === $c->get( 'api.shop.country' ) ) {
|
||||
($c->get('wcgateway.pay-upon-invoice'))->init();
|
||||
( $c->get( 'wcgateway.pay-upon-invoice' ) )->init();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue