Skip to content

Commit

Permalink
Added refund policies for Stripe and PayPal calcom#16858
Browse files Browse the repository at this point in the history
  • Loading branch information
Gyan-max committed Dec 26, 2024
1 parent 5e727a0 commit f1e6826
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 12 deletions.
10 changes: 7 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ CALCOM_PRIVATE_API_ROUTE="https://goblin.cal.com"
# ***********************************************************************************************************

# - DATABASE ************************************************************************************************
DATABASE_URL="postgresql://postgres:br1al4427@@db.svczoobcqrjwrywbsvdi.supabase.co:5432/postgres"
DATABASE_URL="postgresql://postgres:br1al4427@db.ciwadcfcincipaoluwlq.supabase.co:5432/postgres"
# Needed to run migrations while using a connection pooler like PgBouncer
# Use the same one as DATABASE_URL if you're not using a connection pooler
DATABASE_DIRECT_URL=""
Expand Down Expand Up @@ -77,7 +77,7 @@ RESERVED_SUBDOMAINS='"app","auth","docs","design","console","go","status","api",
NEXTAUTH_URL='http://localhost:3000'
# @see: https://next-auth.js.org/configuration/options#nextauth_secret
# You can use: `openssl rand -base64 32` to generate one
NEXTAUTH_SECRET=5QPG+F3A5LyhM+xYh2f9a6LZnME00BI2oBgUO8Yyuk=
NEXTAUTH_SECRET=tafXJZ6r7C70nrMk4/5FjZ8SNi8RQNxkBxZb8vy/a5c=
# Used for cross-domain cookie authentication
NEXTAUTH_COOKIE_DOMAIN=

Expand All @@ -94,7 +94,7 @@ CRON_ENABLE_APP_SYNC=false
# Application Key for symmetric encryption and decryption
# must be 32 bytes for AES256 encryption algorithm
# You can use: `openssl rand -base64 32` to generate one
CALENDSO_ENCRYPTION_KEY=Xf0YyyfBRAHzbrLep81F9RbYWxRLscA+/hpI2Cv0cTU=
CALENDSO_ENCRYPTION_KEY=H7hpXnUhdpGBEb6ZShPWSZ5OZykCD0AI/zhGiJ8AMDg=

# Intercom Config
NEXT_PUBLIC_INTERCOM_APP_ID=
Expand Down Expand Up @@ -413,3 +413,7 @@ REPLEXICA_API_KEY=

# Comma-separated list of DSyncData.directoryId to log SCIM API requests for. It can be enabled temporarily for debugging the requests being sent to SCIM server.
DIRECTORY_IDS_TO_LOG=

# Add any new environment variables related to refund policies
STRIPE_REFUND_POLICY=Standard Refund
PAYPAL_REFUND_POLICY=Flexible Refund
32 changes: 24 additions & 8 deletions config/paymentPolicies.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,32 @@
// Stripe Refund Documentation: https://stripe.com/docs/refunds
// PayPal Refund Documentation: https://developer.paypal.com/docs/api/payments/v2/
const refundPolicies = {
policy1: "Full refund within 30 days of purchase.",
policy2: "50% refund within 60 days of purchase.",
// Add more policies as needed
};

module.exports = {
stripe: {
unconfirmedBooking: true, // Allow refunds for unconfirmed bookings
customerCancellation: true, // Allow refunds for customer cancellations
technicalFailure: true, // Allow refunds for technical failures
unconfirmedBooking: true,
customerCancellation: false,
technicalFailure: true,
policyName: "Stripe Refund Policy",
conditions: "Refunds are processed for unconfirmed bookings and technical failures.",
},
paypal: {
unconfirmedBooking: true, // Allow refunds for unconfirmed bookings
customerCancellation: false, // Do not allow refunds for customer cancellations
technicalFailure: true, // Allow refunds for technical failures
unconfirmedBooking: false,
customerCancellation: false,
technicalFailure: true,
policyName: "PayPal Refund Policy",
conditions: "Refunds are processed for technical failures only.",
},
newPaymentService: {
unconfirmedBooking: false,
customerCancellation: true,
technicalFailure: false,
policyName: "New Service Refund Policy",
conditions: "Refunds allowed for customer cancellations within 45 days.",
},
refundPolicies,
};

module.exports = refundPolicies;
10 changes: 9 additions & 1 deletion packages/prisma/.env
16 changes: 16 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const express = require('express');
const app = express();
const refundPoliciesRoute = require('./routes/refundPolicies');
const { refundPolicies } = require('../config/paymentPolicies');
const { performance } = require('perf_hooks');

// ... other middleware and routes ...

app.use('/api', refundPoliciesRoute);

// Add a new endpoint to serve refund policies
app.get('/api/refund-policies', (req, res) => {
res.json(refundPolicies);
});

// ... server setup ...
26 changes: 26 additions & 0 deletions tests/refundService.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { processRefund } = require('../services/refundService');
const request = require('supertest');
const app = require('../server/index');

// Test cases for refund processing based on defined policies
// Stripe Refund Documentation: https://stripe.com/docs/refunds
Expand All @@ -17,4 +19,28 @@ test('should not process refund for customer cancellation on PayPal', () => {
test('should process refund for technical failure on PayPal', () => {
const booking = { paymentFailed: true };
expect(() => processRefund('paypal', booking)).not.toThrow();
});

test('should process refund for customer cancellation on newPaymentService', () => {
const booking = { cancellationRequested: true };
expect(() => processRefund('newPaymentService', booking)).not.toThrow();
});

test('should not process refund for unconfirmed booking on newPaymentService', () => {
const booking = { status: 'unconfirmed' };
expect(() => processRefund('newPaymentService', booking)).toThrow('Refund not allowed under current policy');
});

test('should not process refund for technical failure on newPaymentService', () => {
const booking = { paymentFailed: true };
expect(() => processRefund('newPaymentService', booking)).toThrow('Refund not allowed under current policy');
});

describe('GET /api/refund-policies', () => {
it('should return refund policies', async () => {
const response = await request(app).get('/api/refund-policies');
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('policy1');
expect(response.body).toHaveProperty('policy2');
});
});

0 comments on commit f1e6826

Please sign in to comment.