Skip to content

Commit c4cb191

Browse files
harlan-zwOrbisK
andauthored
feat: PayPal SDK (#503)
Co-authored-by: Robin Kehl <[email protected]>
1 parent cdc2b98 commit c4cb191

File tree

12 files changed

+729
-7
lines changed

12 files changed

+729
-7
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<template>
2+
<div>
3+
<ScriptPayPalButtons
4+
class="border border-gray-200 dark:border-gray-800 rounded-lg"
5+
:button-options="buttonOptions"
6+
:disabled="disabled"
7+
/>
8+
<label>
9+
Disabled
10+
<input v-model="disabled" type="checkbox">
11+
</label>
12+
<ScriptPayPalMarks />
13+
<ScriptPayPalMessages :messages-options="{ style: { color: 'white-no-border', layout: 'flex' } }" />
14+
</div>
15+
</template>
16+
17+
<script setup lang="ts">
18+
import { computed, ref } from 'vue'
19+
import type { PayPalButtonsComponentOptions } from '@paypal/paypal-js'
20+
21+
const buttonOptions = computed(() => ({
22+
style: {
23+
layout: 'vertical',
24+
color: 'blue',
25+
shape: 'rect',
26+
label: 'paypal',
27+
},
28+
message: { amount: '10.00' },
29+
} satisfies PayPalButtonsComponentOptions))
30+
31+
const disabled = ref(false)
32+
</script>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
::

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
},
7474
"peerDependencies": {
7575
"@stripe/stripe-js": "^7.0.0",
76+
"@paypal/paypal-js": "^8.1.2",
7677
"@types/google.maps": "^3.58.1",
7778
"@types/vimeo__player": "^2.18.3",
7879
"@types/youtube": "^0.1.0",
@@ -82,6 +83,9 @@
8283
"@stripe/stripe-js": {
8384
"optional": true
8485
},
86+
"@paypal/paypal-js": {
87+
"optional": true
88+
},
8589
"@types/google.maps": {
8690
"optional": true
8791
},
@@ -117,6 +121,7 @@
117121
"@nuxt/module-builder": "^1.0.2",
118122
"@nuxt/scripts": "workspace:*",
119123
"@nuxt/test-utils": "3.19.2",
124+
"@paypal/paypal-js": "^8.1.2",
120125
"@types/semver": "^7.7.1",
121126
"@typescript-eslint/typescript-estree": "^8.44.0",
122127
"acorn-loose": "^8.5.2",

playground/pages/index.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ const thirdParties = [
5454
name: 'Stripe',
5555
path: '/third-parties/stripe/nuxt-scripts',
5656
},
57+
{
58+
name: 'PayPal',
59+
path: '/third-parties/paypal/nuxt-scripts',
60+
},
5761
{
5862
name: 'Segment',
5963
path: '/third-parties/segment',
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<template>
2+
<div>
3+
<ScriptPayPalButtons
4+
class="border border-gray-200 dark:border-gray-800 rounded-lg"
5+
:button-options="buttonOptions"
6+
:disabled="disabled"
7+
/>
8+
<label>
9+
Disabled
10+
<input v-model="disabled" type="checkbox">
11+
</label>
12+
<ScriptPayPalMarks />
13+
<ScriptPayPalMessages :messages-options="{ style: { color: 'white-no-border', layout: 'flex' } }" />
14+
</div>
15+
</template>
16+
17+
<script setup lang="ts">
18+
import { computed, ref } from 'vue'
19+
import type { PayPalButtonsComponentOptions } from '@paypal/paypal-js'
20+
21+
const buttonOptions = computed(() => ({
22+
style: {
23+
layout: 'vertical',
24+
color: 'blue',
25+
shape: 'rect',
26+
label: 'paypal',
27+
},
28+
message: { amount: '10.00' },
29+
} satisfies PayPalButtonsComponentOptions))
30+
31+
const disabled = ref(false)
32+
</script>

pnpm-lock.yaml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/registry.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,16 @@ export async function registry(resolve?: (path: string, opts?: ResolvePathOption
214214
from: await resolve('./runtime/registry/lemon-squeezy'),
215215
},
216216
},
217+
{
218+
label: 'PayPal',
219+
src: false, // should not be bundled
220+
category: 'payments',
221+
logo: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 154.728 190.5" xmlns:v="https://vecta.io/nano"><g transform="translate(898.192 276.071)"><path clip-path="none" d="M-837.663-237.968a5.49 5.49 0 0 0-5.423 4.633l-9.013 57.15-8.281 52.514-.005.044.01-.044 8.281-52.514c.421-2.669 2.719-4.633 5.42-4.633h26.404c26.573 0 49.127-19.387 53.246-45.658.314-1.996.482-3.973.52-5.924v-.003h-.003c-6.753-3.543-14.683-5.565-23.372-5.565z" fill="#001c64"/><path clip-path="none" d="M-766.506-232.402c-.037 1.951-.207 3.93-.52 5.926-4.119 26.271-26.673 45.658-53.246 45.658h-26.404c-2.701 0-4.999 1.964-5.42 4.633l-8.281 52.514-5.197 32.947a4.46 4.46 0 0 0 4.405 5.153h28.66a5.49 5.49 0 0 0 5.423-4.633l7.55-47.881c.423-2.669 2.722-4.636 5.423-4.636h16.876c26.573 0 49.124-19.386 53.243-45.655 2.924-18.649-6.46-35.614-22.511-44.026z" fill="#0070e0"/><path clip-path="none" d="M-870.225-276.071a5.49 5.49 0 0 0-5.423 4.636l-22.489 142.608a4.46 4.46 0 0 0 4.405 5.156h33.351l8.281-52.514 9.013-57.15a5.49 5.49 0 0 1 5.423-4.633h47.782c8.691 0 16.621 2.025 23.375 5.563.46-23.917-19.275-43.666-46.412-43.666z" fill="#003087"/></g></svg>`,
222+
import: {
223+
name: 'useScriptPayPal',
224+
from: await resolve('./runtime/registry/paypal'),
225+
},
226+
},
217227
// content
218228
{
219229
label: 'Vimeo Player',

0 commit comments

Comments
 (0)