Merge pull request #398 from woocommerce/pcp-400-show-funding-source

Show "Venmo" instead of "PayPal" when using its' button
This commit is contained in:
Emili Castells 2021-12-14 16:03:01 +01:00 committed by GitHub
commit d5823c1254
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 293 additions and 169 deletions

View file

@ -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') {

View file

@ -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;
});

View file

@ -7,7 +7,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();

View file

@ -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);
}

View file

@ -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;