notice(
'submex_paypal_credentials',
__( 'Submex is not offering a payment method at checkout.', 'submex' ),
$this->paypal_credentials(),
// A different field missing is a different problem, so a dismissed notice comes back for it.
Notice_Dismissals::problem_key( array_keys( self::missing_credentials() ) ),
'paypal'
);
// Separate on purpose: this one does not stop a customer paying, so saying it
// alongside "not offered at checkout" would send the merchant looking for the
// wrong thing entirely.
$this->notice(
'submex_paypal_webhook',
__( 'PayPal renewals will not be recorded.', 'submex' ),
$this->paypal_webhook(),
$this->paypal_webhook() ? 'webhook_id' : '',
'paypal'
);
}
/**
* @param string[] $lines
*/
private function notice( string $id, string $heading, array $lines, string $problem, string $section ): void {
// Asked even with nothing to say, so a fixed problem that comes back shows again.
if ( ! Notice_Dismissals::shows_problem( $id, $lines ? $problem : '' ) ) {
return;
}
echo '
' . esc_html( $heading ) . '
';
foreach ( $lines as $line ) {
echo '- ' . esc_html( $line ) . '
';
}
printf(
'
%s %s
',
esc_url( Settings_Page::section_url( $section ) ),
esc_html__( 'Finish setting it up', 'submex' ),
esc_url( Notice_Dismissals::problem_url( $id, $problem ) ),
esc_html__( 'Dismiss', 'submex' )
);
}
/**
* Credentials decide whether PayPal appears at checkout at all.
*
* @return string[]
*/
private function paypal_credentials(): array {
$missing = self::missing_credentials();
if ( ! $missing ) {
return array();
}
return array(
sprintf(
/* translators: %s: the PayPal fields that are empty. */
__( 'PayPal is switched on but has no %s. Until it does, PayPal is not offered at checkout.', 'submex' ),
implode( __( ' and ', 'submex' ), $missing )
),
);
}
/**
* @return array Option name => what to call it.
*/
private static function missing_credentials(): array {
if ( 'yes' !== get_option( 'submex_paypal_enabled', 'no' ) ) {
return array();
}
$missing = array();
foreach ( array(
'submex_paypal_client_id' => __( 'client ID', 'submex' ),
'submex_paypal_secret' => __( 'secret', 'submex' ),
) as $option => $label ) {
if ( '' === (string) get_option( $option, '' ) ) {
$missing[ $option ] = $label;
}
}
return $missing;
}
/**
* The webhook ID does not gate the checkout: PayPal bills on its own schedule and
* tells Submex by webhook, and an unverifiable webhook is rejected, so every renewal
* goes unrecorded while the customer is charged.
*
* @return string[]
*/
private function paypal_webhook(): array {
if ( 'yes' !== get_option( 'submex_paypal_enabled', 'no' ) || '' !== (string) get_option( 'submex_paypal_webhook_id', '' ) ) {
return array();
}
// Nobody can pay at all without credentials, so promising charges would contradict
// the notice above it.
if ( $this->paypal_credentials() ) {
return array();
}
return array(
__( 'PayPal is switched on but has no webhook ID. Customers can pay, and PayPal will keep charging them, but Submex cannot verify what PayPal sends back — so renewals are rejected and never show against the subscription.', 'submex' ),
);
}
}