Pass total value from observable variable in ngx-paypal

cristid9

I am using ngx-paypal to introduce a paypal pay button in a page. I have the cart object represented like this:

  cart$: Observable<Cart>;

as a local variable. What is the recommended way to to pass the total from cart$ (.total) to the standard config from ngx-paypal:

private initConfig(): void {
    this.payPalConfig = {
      currency: 'EUR',
      clientId: 'AXVj0j1Qk2K6OD2ai7TezGja3QxzK-lAFlTrVT5EiWHL-uFbu3Ce2d2Tg9Jo-13YpiJIzGgNIRkz9lKs',
      createOrderOnClient: (data) => <ICreateOrderRequest> {
        intent: 'CAPTURE',
        purchase_units: [
          {
            amount: {
              currency_code: 'EUR',
              value: this.cart$.totalPriceWithTax.value,
              breakdown: {
                item_total: {
                  currency_code: 'EUR',
                  value: '9.99'
                }
              }
            },
            items: [
              {
                name: 'Enterprise Subscription',
                quantity: '1',
                category: 'DIGITAL_GOODS',
                unit_amount: {
                  currency_code: 'EUR'

Is it ok if I subscribe to cart$ in initConfig and initialize this.payPalConfig inside the subscription?

BizzyBob

If you already have cart$ as an observable and the value of payPalConfig depends on emissions from cart$, it would probably be simplest to define the config as an observable that derives from cart$, something like this:

  public paypalConfig$ = this.cart$.pipe(
    map(cart => this.buildPaypalConfig(cart.items))
  );

You would create a buildPaypalConfig method that builds up the config object, from the cart$ emission. Then, in the template, you can pass paypalConfig$ | async to the ngx-paypal component, like this:

<ngx-paypal [config]="paypalConfig$ | async"></ngx-paypal>

This ensures the ngx-paypal component always has a config that reflects the most up-to-date changes of the cart$.

Here's a StackBlitz sample.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Pass value from php form to Paypal amount

From Dev

Pass value from php form to Paypal amount

From Dev

Pass value from CodeBehind to Angularjs variable

From Dev

pass value of cell from table row to variable

From Dev

pass value/variable from fancybox iframe to parent

From Dev

how to pass value of a variable from javascript to rails

From Dev

Pass the variable and value from python to bash

From Dev

How to pass a value to razor variable from javascript variable?

From Dev

Pass variable value from Text field to variable in iOS

From Dev

Pass value of a include to a variable

From Dev

pass a variable value in crontab

From Dev

how to pass the value of a variable out from its loop in c

From Dev

How can I pass a variable value from one sub to another

From Dev

How to pass value from Javascript to php variable on the second page?

From Dev

How to pass value of date variable from javascript to html

From Dev

How to pass a value of a variable from view to controller in codeigniter

From Dev

Select one value from table and pass it to variable - php mysql

From Dev

Pass dynamic variable value from robot framework to python file

From Dev

How to assign or pass value to the instance variable in controller from rspec controller?

From Dev

How to pass variable value from one function to another

From Dev

How to pass value from JavaScript function to PHP variable?

From Dev

(Shell Script) Variable not pass correctly when fetching value from file?

From Dev

How can I pass the value coming from a jQuery variable to PHP?

From Dev

How to pass the variable value from function to calling procedure in Shellscript

From Dev

Pass value from Django to Ajax, how to identify variable type?

From Dev

Get value of variable from activity and pass it to fragment activity

From Dev

How to pass local variable value from function to addEventListener function?

From Dev

select an item from FlatList and pass the value to a variable state

From Dev

PHP pass total value of radio button

Related Related

  1. 1

    Pass value from php form to Paypal amount

  2. 2

    Pass value from php form to Paypal amount

  3. 3

    Pass value from CodeBehind to Angularjs variable

  4. 4

    pass value of cell from table row to variable

  5. 5

    pass value/variable from fancybox iframe to parent

  6. 6

    how to pass value of a variable from javascript to rails

  7. 7

    Pass the variable and value from python to bash

  8. 8

    How to pass a value to razor variable from javascript variable?

  9. 9

    Pass variable value from Text field to variable in iOS

  10. 10

    Pass value of a include to a variable

  11. 11

    pass a variable value in crontab

  12. 12

    how to pass the value of a variable out from its loop in c

  13. 13

    How can I pass a variable value from one sub to another

  14. 14

    How to pass value from Javascript to php variable on the second page?

  15. 15

    How to pass value of date variable from javascript to html

  16. 16

    How to pass a value of a variable from view to controller in codeigniter

  17. 17

    Select one value from table and pass it to variable - php mysql

  18. 18

    Pass dynamic variable value from robot framework to python file

  19. 19

    How to assign or pass value to the instance variable in controller from rspec controller?

  20. 20

    How to pass variable value from one function to another

  21. 21

    How to pass value from JavaScript function to PHP variable?

  22. 22

    (Shell Script) Variable not pass correctly when fetching value from file?

  23. 23

    How can I pass the value coming from a jQuery variable to PHP?

  24. 24

    How to pass the variable value from function to calling procedure in Shellscript

  25. 25

    Pass value from Django to Ajax, how to identify variable type?

  26. 26

    Get value of variable from activity and pass it to fragment activity

  27. 27

    How to pass local variable value from function to addEventListener function?

  28. 28

    select an item from FlatList and pass the value to a variable state

  29. 29

    PHP pass total value of radio button

HotTag

Archive