mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Show "Venmo" instead of "PayPal" when using its' button
This commit is contained in:
parent
cf5d1ec21f
commit
f4a32a01e7
8 changed files with 155 additions and 161 deletions
|
@ -14,7 +14,10 @@ const bootstrap = () => {
|
|||
const errorHandler = new ErrorHandler(PayPalCommerceGateway.labels.error.generic);
|
||||
const spinner = new Spinner();
|
||||
const creditCardRenderer = new CreditCardRenderer(PayPalCommerceGateway, errorHandler, spinner);
|
||||
const renderer = new Renderer(creditCardRenderer, PayPalCommerceGateway);
|
||||
const onSmartButtonClick = data => {
|
||||
window.ppcpFundingSource = data.fundingSource;
|
||||
};
|
||||
const renderer = new Renderer(creditCardRenderer, PayPalCommerceGateway, onSmartButtonClick);
|
||||
const messageRenderer = new MessageRenderer(PayPalCommerceGateway.messages);
|
||||
const context = PayPalCommerceGateway.context;
|
||||
if (context === 'mini-cart' || context === 'product') {
|
||||
|
|
|
@ -4,7 +4,8 @@ const onApprove = (context, errorHandler) => {
|
|||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
nonce: context.config.ajax.approve_order.nonce,
|
||||
order_id:data.orderID
|
||||
order_id:data.orderID,
|
||||
funding_source: window.ppcpFundingSource,
|
||||
})
|
||||
}).then((res)=>{
|
||||
return res.json();
|
||||
|
@ -13,7 +14,7 @@ const onApprove = (context, errorHandler) => {
|
|||
errorHandler.genericError();
|
||||
return actions.restart().catch(err => {
|
||||
errorHandler.genericError();
|
||||
});;
|
||||
});
|
||||
}
|
||||
location.href = context.config.redirect;
|
||||
});
|
||||
|
|
|
@ -5,7 +5,8 @@ const onApprove = (context, errorHandler, spinner) => {
|
|||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
nonce: context.config.ajax.approve_order.nonce,
|
||||
order_id:data.orderID
|
||||
order_id:data.orderID,
|
||||
funding_source: window.ppcpFundingSource,
|
||||
})
|
||||
}).then((res)=>{
|
||||
return res.json();
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
class Renderer {
|
||||
constructor(creditCardRenderer, defaultConfig) {
|
||||
constructor(creditCardRenderer, defaultConfig, onSmartButtonClick) {
|
||||
this.defaultConfig = defaultConfig;
|
||||
this.creditCardRenderer = creditCardRenderer;
|
||||
this.onSmartButtonClick = onSmartButtonClick;
|
||||
}
|
||||
|
||||
render(wrapper, hostedFieldsWrapper, contextConfig) {
|
||||
|
@ -19,6 +20,7 @@ class Renderer {
|
|||
paypal.Buttons({
|
||||
style,
|
||||
...contextConfig,
|
||||
onClick: this.onSmartButtonClick,
|
||||
}).render(wrapper);
|
||||
}
|
||||
|
||||
|
|
|
@ -184,6 +184,9 @@ class ApproveOrderEndpoint implements EndpointInterface {
|
|||
throw new RuntimeException( $message );
|
||||
}
|
||||
|
||||
$funding_source = $data['funding_source'] ?? null;
|
||||
$this->session_handler->replace_funding_source( $funding_source );
|
||||
|
||||
$this->session_handler->replace_order( $order );
|
||||
wp_send_json_success( $order );
|
||||
return true;
|
||||
|
|
|
@ -40,6 +40,13 @@ class SessionHandler {
|
|||
*/
|
||||
private $insufficient_funding_tries = 0;
|
||||
|
||||
/**
|
||||
* The funding source of the current checkout (venmo, ...) or null.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
private $funding_source = null;
|
||||
|
||||
/**
|
||||
* Returns the order.
|
||||
*
|
||||
|
@ -84,6 +91,28 @@ class SessionHandler {
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the funding source of the current checkout (venmo, ...) or null.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function funding_source(): ?string {
|
||||
return $this->funding_source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the funding source of the current checkout.
|
||||
*
|
||||
* @param string|null $funding_source The funding source.
|
||||
*
|
||||
* @return SessionHandler
|
||||
*/
|
||||
public function replace_funding_source( ?string $funding_source ): SessionHandler {
|
||||
$this->funding_source = $funding_source;
|
||||
$this->store_session();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns how many times the customer tried to use the PayPal Gateway in this session.
|
||||
*
|
||||
|
@ -113,6 +142,7 @@ class SessionHandler {
|
|||
$this->order = null;
|
||||
$this->bn_code = '';
|
||||
$this->insufficient_funding_tries = 0;
|
||||
$this->funding_source = null;
|
||||
$this->store_session();
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -241,6 +241,12 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
$this->description = $this->config->has( 'description' ) ?
|
||||
$this->config->get( 'description' ) : $this->method_description;
|
||||
|
||||
$funding_source = $this->session_handler->funding_source();
|
||||
if ( 'venmo' === $funding_source ) {
|
||||
$this->title = 'Venmo';
|
||||
$this->description = __( 'Pay via Venmo.', 'woocommerce-paypal-payments' );
|
||||
}
|
||||
|
||||
$this->init_form_fields();
|
||||
$this->init_settings();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue