|
| 1 | +--- |
| 2 | +title: PayPal |
| 3 | +description: Use PayPal in your Nuxt app. |
| 4 | +links: |
| 5 | + - label: useScriptPayPal |
| 6 | + icon: i-simple-icons-github |
| 7 | + to: https://github.com/nuxt/scripts/blob/main/src/runtime/registry/paypal.ts |
| 8 | + size: xs |
| 9 | + - label: "<ScriptPayPalButtons>" |
| 10 | + icon: i-simple-icons-github |
| 11 | + to: https://github.com/nuxt/scripts/blob/main/src/runtime/components/ScriptPayPalButtons.vue |
| 12 | + size: xs |
| 13 | + - label: "<ScriptPayPalMarks>" |
| 14 | + icon: i-simple-icons-github |
| 15 | + to: https://github.com/nuxt/scripts/blob/main/src/runtime/components/ScriptPayPalMarks.vue |
| 16 | + size: xs |
| 17 | + - label: "<ScriptPayPalMessages>" |
| 18 | + icon: i-simple-icons-github |
| 19 | + to: https://github.com/nuxt/scripts/blob/main/src/runtime/components/ScriptPayPalMessages.vue |
| 20 | + size: xs |
| 21 | +--- |
| 22 | + |
| 23 | +[PayPal](https://www.paypal.com) is a popular payment gateway that allows you to accept payments online. |
| 24 | + |
| 25 | +Nuxt Scripts provides multiple PayPal features: |
| 26 | +- `useScriptPayPal` composable which loads the script `https://www.paypal.com/sdk/js`. |
| 27 | +- `ScriptPayPalButtons` component that allows you to embed [PayPal Buttons](https://developer.paypal.com/sdk/js/reference/#buttons) on your site. |
| 28 | +- `ScriptPayPalMarks` component that allows you to embed [PayPal Marks](https://developer.paypal.com/sdk/js/reference/#marks) on your site. |
| 29 | +- `ScriptPayPalMessages` component that allows you to embed [PayPal Messages](https://developer.paypal.com/studio/checkout/pay-later/us/customize/reference) on your site. |
| 30 | + |
| 31 | +## Types |
| 32 | + |
| 33 | +To use the PayPal with full TypeScript support, you will need |
| 34 | +to install the `@paypal/paypal-js` dependency. |
| 35 | + |
| 36 | +```bash |
| 37 | +pnpm add -D @paypal/paypal-js |
| 38 | +``` |
| 39 | +### Demo |
| 40 | + |
| 41 | +::code-group |
| 42 | + |
| 43 | +:pay-pal-demo{label="Output"} |
| 44 | + |
| 45 | +```vue [Input] |
| 46 | +<template> |
| 47 | + <div> |
| 48 | + <ScriptPayPalButtons |
| 49 | + class="border border-gray-200 dark:border-gray-800 rounded-lg" |
| 50 | + :button-options="buttonOptions" |
| 51 | + :disabled="disabled" |
| 52 | + /> |
| 53 | + <label> |
| 54 | + Disabled |
| 55 | + <input v-model="disabled" type="checkbox"> |
| 56 | + </label> |
| 57 | + <ScriptPayPalMarks /> |
| 58 | + <ScriptPayPalMessages :messages-options="{ style: { color: 'white-no-border', layout: 'flex' } }" /> |
| 59 | + </div> |
| 60 | +</template> |
| 61 | +
|
| 62 | +<script setup lang="ts"> |
| 63 | + import { computed, ref } from 'vue' |
| 64 | + import type { PayPalButtonsComponentOptions } from '@paypal/paypal-js' |
| 65 | +
|
| 66 | + const buttonOptions = computed(() => ({ |
| 67 | + style: { |
| 68 | + layout: 'vertical', |
| 69 | + color: 'blue', |
| 70 | + shape: 'rect', |
| 71 | + label: 'paypal', |
| 72 | + }, |
| 73 | + message: { amount: '10.00' }, |
| 74 | + } satisfies PayPalButtonsComponentOptions)) |
| 75 | +
|
| 76 | + const disabled = ref(false) |
| 77 | +</script> |
| 78 | +``` |
| 79 | + |
| 80 | +:: |
0 commit comments