@foxses/pay-paypal
v1.0.0
Published
PayPal payment provider for foxses-pay
Readme
@foxses/pay-paypal
PayPal payment provider for foxses-pay.
Accept card payments and PayPal wallet payments globally.
Install
npm install @foxses/pay-core @foxses/pay-paypalOr use the all-in-one package:
npm install @foxses/payUsage
import { PaymentGateway } from "@foxses/pay-core";
import "@foxses/pay-paypal";
const gateway = new PaymentGateway();
gateway.use("paypal", {
clientId: "YOUR_PAYPAL_CLIENT_ID",
clientSecret: "YOUR_PAYPAL_CLIENT_SECRET",
successUrl: "https://yoursite.com/success",
failureUrl: "https://yoursite.com/cancel",
sandbox: true, // false for production
});
// Step 1: Create order
const payment = await gateway.createPayment("paypal", {
amount: 29.99,
currency: "USD",
orderId: "ORDER-001",
});
// Redirect user to:
console.log(payment.checkoutUrl); // PayPal checkout page
// Step 2: Verify after PayPal redirects back with ?token=ORDER_ID
const result = await gateway.verifyPayment("paypal", {
transactionId: orderId, // from query param or stored value
});
console.log(result.status); // "completed"
// Step 3: Refund (uses capture ID)
const refund = await gateway.refundPayment("paypal", {
transactionId: "CAPTURE_ID",
amount: 29.99,
});Getting Credentials
- Go to developer.paypal.com
- Apps & Credentials → Create App
- Copy Client ID and Client Secret
Sandbox: use sandbox credentials with sandbox: true
Documentation
paydoc.foxses.com/docs/providers/paypal
License
MIT © Foxses Studio
