mirror of
https://github.com/duhanbalci/iyzico.git
synced 2026-03-03 20:29:18 +00:00
194 lines
6.0 KiB
TypeScript
194 lines
6.0 KiB
TypeScript
/**
|
|
* Subscription test fixtures with randomized personal data
|
|
*/
|
|
|
|
import { faker } from '@faker-js/faker';
|
|
import type {
|
|
ProductCreateRequest,
|
|
PricingPlanCreateRequest,
|
|
SubscriptionCustomer,
|
|
SubscriptionPaymentCard,
|
|
SubscriptionAddress,
|
|
SubscriptionInitializeRequest,
|
|
SubscriptionCheckoutFormInitializeRequest,
|
|
} from '../../src/types';
|
|
|
|
/**
|
|
* Generates a valid Turkish identity number (TC Kimlik No)
|
|
*/
|
|
function generateTurkishIdentityNumber(): string {
|
|
const digits: number[] = [];
|
|
|
|
// First digit cannot be 0
|
|
digits.push(faker.number.int({ min: 1, max: 9 }));
|
|
|
|
// Generate next 8 random digits
|
|
for (let i = 1; i < 9; i++) {
|
|
digits.push(faker.number.int({ min: 0, max: 9 }));
|
|
}
|
|
|
|
// Calculate 10th digit
|
|
const oddSum = digits[0] + digits[2] + digits[4] + digits[6] + digits[8];
|
|
const evenSum = digits[1] + digits[3] + digits[5] + digits[7];
|
|
const digit10 = (oddSum * 7 - evenSum) % 10;
|
|
digits.push(digit10 < 0 ? digit10 + 10 : digit10);
|
|
|
|
// Calculate 11th digit
|
|
const allSum = digits.reduce((sum, d) => sum + d, 0);
|
|
digits.push(allSum % 10);
|
|
|
|
return digits.join('');
|
|
}
|
|
|
|
/**
|
|
* Generates a Turkish phone number in the format +905XXXXXXXXX
|
|
*/
|
|
function generateTurkishPhoneNumber(): string {
|
|
const areaCode = faker.helpers.arrayElement(['530', '531', '532', '533', '534', '535', '536', '537', '538', '539', '540', '541', '542', '543', '544', '545', '546', '547', '548', '549', '550', '551', '552', '553', '554', '555', '556', '557', '558', '559']);
|
|
const number = faker.string.numeric(7);
|
|
return `+90${areaCode}${number}`;
|
|
}
|
|
|
|
/**
|
|
* Generates a subscription billing address with randomized data
|
|
*/
|
|
export function createTestSubscriptionBillingAddress(): SubscriptionAddress {
|
|
return {
|
|
address: `${faker.location.streetAddress()}, ${faker.location.city()}`,
|
|
zipCode: faker.location.zipCode('#####'),
|
|
contactName: faker.person.fullName(),
|
|
city: faker.location.city(),
|
|
country: 'Turkey',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Generates a subscription shipping address with randomized data
|
|
*/
|
|
export function createTestSubscriptionShippingAddress(): SubscriptionAddress {
|
|
return {
|
|
address: `${faker.location.streetAddress()}, ${faker.location.city()}`,
|
|
zipCode: faker.location.zipCode('#####'),
|
|
contactName: faker.person.fullName(),
|
|
city: faker.location.city(),
|
|
country: 'Turkey',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Generates a subscription customer with randomized personal data
|
|
*/
|
|
export function createTestSubscriptionCustomer(): SubscriptionCustomer {
|
|
const firstName = faker.person.firstName();
|
|
const lastName = faker.person.lastName();
|
|
|
|
return {
|
|
name: firstName,
|
|
surname: lastName,
|
|
email: faker.internet.email({ firstName, lastName }).toLowerCase(),
|
|
gsmNumber: generateTurkishPhoneNumber(),
|
|
identityNumber: generateTurkishIdentityNumber(),
|
|
billingAddress: createTestSubscriptionBillingAddress(),
|
|
shippingAddress: createTestSubscriptionShippingAddress(),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Generates a subscription payment card with randomized holder name
|
|
* Card number is fixed to iyzico sandbox test card
|
|
*/
|
|
export function createTestSubscriptionPaymentCard(): SubscriptionPaymentCard {
|
|
return {
|
|
cardHolderName: faker.person.fullName(),
|
|
cardNumber: '5528790000000008', // iyzico sandbox test card
|
|
expireMonth: '12',
|
|
expireYear: '2030',
|
|
cvc: '123',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Generates a product create request with unique name
|
|
*/
|
|
export function createTestProductCreateRequest(): ProductCreateRequest {
|
|
return {
|
|
locale: 'tr',
|
|
name: `Test ${faker.string.alphanumeric(6)}`,
|
|
description: faker.commerce.productDescription().substring(0,20),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Generates a pricing plan create request
|
|
*/
|
|
export function createTestPricingPlanCreateRequest(): PricingPlanCreateRequest {
|
|
return {
|
|
locale: 'tr',
|
|
name: `Monthly Test Plan ${faker.string.alphanumeric(6)}`,
|
|
price: 99.99,
|
|
currencyCode: 'TRY',
|
|
paymentInterval: 'MONTHLY',
|
|
paymentIntervalCount: 1,
|
|
trialPeriodDays: 7,
|
|
planPaymentType: 'RECURRING',
|
|
recurrenceCount: 12,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Generates a subscription initialize request with randomized data
|
|
*/
|
|
export function createTestSubscriptionInitializeRequest(pricingPlanReferenceCode: string = ''): SubscriptionInitializeRequest {
|
|
return {
|
|
locale: 'tr',
|
|
pricingPlanReferenceCode,
|
|
subscriptionInitialStatus: 'ACTIVE',
|
|
customer: createTestSubscriptionCustomer(),
|
|
paymentCard: createTestSubscriptionPaymentCard(),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Generates a subscription checkout form request with randomized data
|
|
*/
|
|
export function createTestSubscriptionCheckoutFormRequest(pricingPlanReferenceCode: string = ''): SubscriptionCheckoutFormInitializeRequest {
|
|
return {
|
|
locale: 'tr',
|
|
callbackUrl: 'https://www.merchant.com/callback',
|
|
pricingPlanReferenceCode,
|
|
subscriptionInitialStatus: 'ACTIVE',
|
|
customer: createTestSubscriptionCustomer(),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Generates a unique product name for testing
|
|
*/
|
|
export function generateTestProductName(): string {
|
|
return `Test Product ${Date.now()}-${faker.string.alphanumeric(4)}`;
|
|
}
|
|
|
|
/**
|
|
* Generates a unique pricing plan name for testing
|
|
*/
|
|
export function generateTestPlanName(): string {
|
|
return `Test Plan ${Date.now()}-${faker.string.alphanumeric(4)}`;
|
|
}
|
|
|
|
/**
|
|
* Generates a unique email for testing
|
|
*/
|
|
export function generateTestEmail(): string {
|
|
return faker.internet.email().toLowerCase();
|
|
}
|
|
|
|
// Legacy exports for backward compatibility (static versions that generate once)
|
|
export const testSubscriptionBillingAddress = createTestSubscriptionBillingAddress();
|
|
export const testSubscriptionShippingAddress = createTestSubscriptionShippingAddress();
|
|
export const testSubscriptionCustomer = createTestSubscriptionCustomer();
|
|
export const testSubscriptionPaymentCard = createTestSubscriptionPaymentCard();
|
|
export const testProductCreateRequest = createTestProductCreateRequest();
|
|
export const testPricingPlanCreateRequest = createTestPricingPlanCreateRequest();
|
|
export const testSubscriptionInitializeRequest = createTestSubscriptionInitializeRequest();
|
|
export const testSubscriptionCheckoutFormRequest = createTestSubscriptionCheckoutFormRequest();
|