mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
✨ New option to configure BN-Code
Configurable via a wp-config constant, or a new wp-filter.
This commit is contained in:
parent
34245a852b
commit
6efcaa5630
7 changed files with 57 additions and 12 deletions
|
@ -42,7 +42,7 @@ trait RequestTrait {
|
|||
*/
|
||||
$args = apply_filters( 'ppcp_request_args', $args, $url );
|
||||
if ( ! isset( $args['headers']['PayPal-Partner-Attribution-Id'] ) ) {
|
||||
$args['headers']['PayPal-Partner-Attribution-Id'] = 'Woo_PPCP';
|
||||
$args['headers']['PayPal-Partner-Attribution-Id'] = PPCP_PAYPAL_BN_CODE;
|
||||
}
|
||||
|
||||
$response = wp_remote_get( $url, $args );
|
||||
|
|
|
@ -818,7 +818,14 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
|
|||
*/
|
||||
do_action( "ppcp_before_{$location_hook}_message_wrapper" );
|
||||
|
||||
$messages_placeholder = '<div class="ppcp-messages" data-partner-attribution-id="Woo_PPCP"></div>';
|
||||
/**
|
||||
* The BN code.
|
||||
*
|
||||
* @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE
|
||||
*/
|
||||
$bn_code = PPCP_PAYPAL_BN_CODE;
|
||||
|
||||
$messages_placeholder = '<div class="ppcp-messages" data-partner-attribution-id="' . esc_attr( $bn_code ) . '"></div>';
|
||||
|
||||
if ( is_array( $block_params ) && ( $block_params['blockName'] ?? false ) ) {
|
||||
$this->render_after_block(
|
||||
|
@ -1538,7 +1545,15 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
|
|||
private function bn_code_for_context( string $context ): string {
|
||||
|
||||
$codes = $this->bn_codes();
|
||||
return ( isset( $codes[ $context ] ) ) ? $codes[ $context ] : 'Woo_PPCP';
|
||||
|
||||
/**
|
||||
* The BN code.
|
||||
*
|
||||
* @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE
|
||||
*/
|
||||
$bn_code = PPCP_PAYPAL_BN_CODE;
|
||||
|
||||
return ( isset( $codes[ $context ] ) ) ? $codes[ $context ] : $bn_code;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1546,13 +1561,19 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
private function bn_codes(): array {
|
||||
private function bn_codes() : array {
|
||||
/**
|
||||
* The BN code.
|
||||
*
|
||||
* @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE
|
||||
*/
|
||||
$bn_code = PPCP_PAYPAL_BN_CODE;
|
||||
|
||||
return array(
|
||||
'checkout' => 'Woo_PPCP',
|
||||
'cart' => 'Woo_PPCP',
|
||||
'mini-cart' => 'Woo_PPCP',
|
||||
'product' => 'Woo_PPCP',
|
||||
'checkout' => $bn_code,
|
||||
'cart' => $bn_code,
|
||||
'mini-cart' => $bn_code,
|
||||
'product' => $bn_code,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,14 @@ class PayLaterBlockRenderer {
|
|||
public function render( array $attributes, ContainerInterface $c ): string {
|
||||
if ( PayLaterBlockModule::is_block_enabled( $c->get( 'wcgateway.settings.status' ) ) ) {
|
||||
|
||||
$html = '<div id="' . esc_attr( $attributes['id'] ?? '' ) . '" class="ppcp-messages" data-partner-attribution-id="Woo_PPCP"></div>';
|
||||
/**
|
||||
* The BN code.
|
||||
*
|
||||
* @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE
|
||||
*/
|
||||
$bn_code = PPCP_PAYPAL_BN_CODE;
|
||||
|
||||
$html = '<div id="' . esc_attr( $attributes['id'] ?? '' ) . '" class="ppcp-messages" data-partner-attribution-id="' . esc_attr( $bn_code ) . '"></div>';
|
||||
|
||||
$processor = new \WP_HTML_Tag_Processor( $html );
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
merchantClientId: PcpPayLaterConfigurator.merchantClientId,
|
||||
partnerClientId: PcpPayLaterConfigurator.partnerClientId,
|
||||
partnerName: 'WooCommerce',
|
||||
bnCode: 'Woo_PPCP',
|
||||
bnCode: PcpPayLaterConfigurator.bnCode,
|
||||
placements: ['cart', 'checkout', 'product', 'shop', 'home', 'custom_placement'],
|
||||
styleOverrides: {
|
||||
button: publishButtonClassName,
|
||||
|
|
|
@ -113,6 +113,13 @@ class PayLaterConfiguratorModule implements ModuleInterface {
|
|||
$config_factory = $c->get( 'paylater-configurator.factory.config' );
|
||||
assert( $config_factory instanceof ConfigFactory );
|
||||
|
||||
/**
|
||||
* The BN code.
|
||||
*
|
||||
* @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE
|
||||
*/
|
||||
$bn_code = PPCP_PAYPAL_BN_CODE;
|
||||
|
||||
wp_localize_script(
|
||||
'ppcp-paylater-configurator',
|
||||
'PcpPayLaterConfigurator',
|
||||
|
@ -130,6 +137,7 @@ class PayLaterConfiguratorModule implements ModuleInterface {
|
|||
'config' => $config_factory->from_settings( $settings ),
|
||||
'merchantClientId' => $settings->get( 'client_id' ),
|
||||
'partnerClientId' => $c->get( 'api.partner_merchant_id' ),
|
||||
'bnCode' => $bn_code,
|
||||
'publishButtonClassName' => 'ppcp-paylater-configurator-publishButton',
|
||||
'headerClassName' => 'ppcp-paylater-configurator-header',
|
||||
'subheaderClassName' => 'ppcp-paylater-configurator-subheader',
|
||||
|
|
|
@ -95,14 +95,21 @@ class PayLaterWCBlocksRenderer {
|
|||
) {
|
||||
if ( PayLaterWCBlocksModule::is_placement_enabled( $c->get( 'wcgateway.settings.status' ), $location ) ) {
|
||||
|
||||
$html = '<div id="' . esc_attr( $attributes['ppcpId'] ?? '' ) . '" class="ppcp-messages" data-partner-attribution-id="Woo_PPCP"></div>';
|
||||
/**
|
||||
* The BN code.
|
||||
*
|
||||
* @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE
|
||||
*/
|
||||
$bn_code = PPCP_PAYPAL_BN_CODE;
|
||||
|
||||
$html = '<div id="' . esc_attr( $attributes['ppcpId'] ?? '' ) . '" class="ppcp-messages" data-partner-attribution-id="' . esc_attr( $bn_code ) . '"></div>';
|
||||
|
||||
$processor = new \WP_HTML_Tag_Processor( $html );
|
||||
|
||||
if ( $processor->next_tag( 'div' ) ) {
|
||||
$processor->set_attribute( 'data-block-name', esc_attr( $attributes['blockId'] ?? '' ) );
|
||||
$processor->set_attribute( 'class', 'ppcp-messages' );
|
||||
$processor->set_attribute( 'data-partner-attribution-id', 'Woo_PPCP' );
|
||||
$processor->set_attribute( 'data-partner-attribution-id', $bn_code );
|
||||
|
||||
if ( $this->layout === 'flex' ) {
|
||||
$processor->set_attribute( 'data-pp-style-layout', 'flex' );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue