This integration uses the JavaScript SDK to accept Paidy payments
See a hosted version of the sample
-
Clone the repo
git clone [email protected]:paypal-examples/paidy.git
-
Copy the .env.example file into a file named .env
cp .env.example .env
-
Run
npm install
-
configure your
.env
config file with your Paypal (Sandbox)CLIENT_ID
andCLIENT_SECRET
these can be obtained here
-
Update
client/index.html
script srcclientId
paramhttps://www.paypal.com/sdk/js?client-id=<CLIENT_ID>&...
-
npm start
.
-
Run
npm run webhook-proxy
take note of thewebhookId
. -
Update your
.env
fileWEBHOOK_ID
value. -
Restart the server
npm start
Loading the JavaScript SDK
The sdk requires the following query params to be configured on the script src to accept paidy payments.
Param | Value |
---|---|
client-id | PayPal ClientId |
components | buttons,fields,marks,funding-eligibility |
enable-funding | paidy |
currency | JPY |
Example:
<script src="https://www.paypal.com/sdk/js?client-id=<CLIENT_ID>&components=buttons,fields,marks,funding-eligibility&enable-funding=paidy¤cy=JPY"></script>
Please note Paidy orders are required to be created in JPY
{
purchase_units: [
{
amount: {
currency_code: "JPY",
value: "49"
}
}
],
payment_source: {
paidy: {
name": "山田 太郎",
country_code: "JP",
experience_context: {
logo_url: "https://example.com/logo.jpg",
locale: "ja-JP",
return_url: `${window.location.origin}/success`,
cancel_url: `${window.location.origin}/cancel`
}
}
}
}
Mark
paypal
.Marks({
fundingSource: paypal.FUNDING.PAIDY
})
.render("#paidy-mark");
PaymentFields
Render the fields to capture required customer information.
It gives the option to prefil the customer name field if this is already obtained via fields.name.value
property.
paypal
.PaymentFields({
fundingSource: paypal.FUNDING.PAIDY,
style: {},
fields: {
name: {
value: "",
},
},
})
.render("#paidy-fields");
Style object:
const style = {
base: {
backgroundColor: "white",
color: "black",
fontSize: "16px",
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
lineHeight: "1.4",
letterSpacing: "0.3"
},
input: {
backgroundColor: "white",
fontSize: "16px",
color: "#333",
borderColor: "#dbdbdb",
borderRadius: "4px",
borderWidth: "1px",
padding: "1rem"
},
invalid: {
color: "red"
},
active: {
color: "black"
}
}
Button
paypal
.Buttons({
fundingSource: paypal.FUNDING.PAIDY,
style: {
label: "pay"
},
createOrder(data, actions) {
/* see order payload info */
return actions.order.create(order);
},
onApprove(data, actions) {
console.log("order approved")
},
onCancel(data, actions) {
console.log("onCancel called");
},
onError(err) {
console.error(err);
}
})
.render("#paidy-btn");