@foxses/pay-stripe
v1.0.1
Published
Stripe payment provider for foxses-pay
Readme
@foxses/pay-stripe
Stripe Checkout Session provider for foxses-pay.
Install
npm install @foxses/pay-core @foxses/pay-stripeOr use the all-in-one package:
npm install @foxses/payUsage
import { PaymentGateway } from "@foxses/pay-core";
import "@foxses/pay-stripe";
const gateway = new PaymentGateway();
gateway.use("stripe", {
apiKey: "sk_test_YOUR_SECRET_KEY",
webhookSecret: "whsec_YOUR_WEBHOOK_SECRET", // optional
successUrl: "https://yoursite.com/success",
failureUrl: "https://yoursite.com/cancel",
sandbox: true,
});
// Step 1: Create Checkout Session
const payment = await gateway.createPayment("stripe", {
amount: 29.99,
currency: "USD",
orderId: "ORDER-001",
customerEmail: "[email protected]",
metadata: { productName: "Pro Plan" },
});
// Redirect user to:
console.log(payment.checkoutUrl);
// Step 2: Verify after Stripe redirects to successUrl with ?session_id=cs_xxx
const result = await gateway.verifyPayment("stripe", {
transactionId: session_id,
amount: 29.99,
});
console.log(result.status); // "completed"
console.log(result.transactionId); // pi_xxx — Payment Intent ID
// Step 3: Refund (needs payment intent ID)
const refund = await gateway.refundPayment("stripe", {
transactionId: "pi_PAYMENT_INTENT_ID",
amount: 29.99,
});Test Cards
| Scenario | Card | |----------|------| | Success | 4242 4242 4242 4242 | | Decline | 4000 0000 0000 9995 |
Use any future expiry date and any 3-digit CVV.
Documentation
paydoc.foxses.com/docs/providers/stripe
License
MIT © Foxses Studio
