Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Add a PayPal messaging component partial #275

Merged
merged 1 commit into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ using the
[Vault flow](https://developers.braintreepayments.com/guides/paypal/overview/javascript/v3),
which allows the source to be reused. If you want, you can use [Checkout with PayPal](https://developers.braintreepayments.com/guides/paypal/checkout-with-paypal/javascript/v3)
instead, which doesn't allow you to reuse sources but allows your customers to pay with their PayPal
balance (see setup instructions).
balance and with PayPal financing options ([see setup instructions](#create-a-new-payment-method)).

If you are creating your own checkout view or would like to customize the
[options that get passed to tokenize](https://braintree.github.io/braintree-web/3.6.3/PayPal.html#tokenize)
Expand All @@ -188,6 +188,15 @@ A PayPal button can also be included on the cart view to enable express checkout
render "spree/shared/paypal_cart_button"
```

### PayPal Financing Messaging

PayPal offers an [on-site messaging component](https://www.paypal.com/us/webapps/mpp/on-site-messaging) to notify the customer that there are financing options available. By default, this component is used in both the cart and checkout partials.

You can also include this view partial to implement this messaging component anywhere - for instance, on the product page:
```ruby
render "spree/shared/paypal_messaging, options: {total: @product.price, placement: "product", currency: 'USD'}"
```

#### PayPal configuration

If your store requires the [phone number into user addresses](https://github.com/solidusio/solidus/blob/859143f3f061de79cc1b385234599422b8ae8e21/core/app/models/spree/address.rb#L151-L153)
Expand Down
8 changes: 8 additions & 0 deletions app/assets/javascripts/solidus_paypal_braintree/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ SolidusPaypalBraintree = {
return SolidusPaypalBraintree.PaypalButton;
},

paypalMessaging: function() {
return SolidusPaypalBraintree.PaypalMessaging;
},

applepayButton: function() {
return SolidusPaypalBraintree.ApplepayButton;
}
Expand All @@ -51,6 +55,10 @@ SolidusPaypalBraintree = {
return SolidusPaypalBraintree._factory(SolidusPaypalBraintree.config.classes.paypalButton(), arguments);
},

createPaypalMessaging: function() {
return SolidusPaypalBraintree._factory(SolidusPaypalBraintree.config.classes.paypalMessaging(), arguments);
},

createApplePayButton: function() {
return SolidusPaypalBraintree._factory(SolidusPaypalBraintree.config.classes.applepayButton(), arguments);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
//= require solidus_paypal_braintree/client
//= require solidus_paypal_braintree/hosted_form
//= require solidus_paypal_braintree/paypal_button
//= require solidus_paypal_braintree/paypal_messaging
//= require solidus_paypal_braintree/apple_pay_button
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//= require solidus_paypal_braintree/constants

SolidusPaypalBraintree.PaypalMessaging = function(paypalOptions) {
this._paypalOptions = paypalOptions || {};

this._client = null;
};

SolidusPaypalBraintree.PaypalMessaging.prototype.initialize = function() {
this._client = new SolidusPaypalBraintree.createClient({usePaypal: true});

return this._client.initialize().then(this.initializeCallback.bind(this));
};

SolidusPaypalBraintree.PaypalMessaging.prototype.initializeCallback = function() {
this._paymentMethodId = this._client.paymentMethodId;

this._client.getPaypalInstance().loadPayPalSDK({
currency: this._paypalOptions.currency,
components: "messages"
})
};
13 changes: 13 additions & 0 deletions app/views/spree/shared/_paypal_messaging.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%= render "spree/shared/paypal_braintree_head_scripts" %>

<div data-pp-message data-pp-placement="<%= options[:placement] %>" data-pp-amount="<%= options[:total] %>"></div>

<script>
var message = new SolidusPaypalBraintree.createPaypalMessaging(
{
currency: "<%= options[:currency] %>"
}
)

message.initialize();
</script>