mirror of
https://github.com/duhanbalci/iyzico.git
synced 2026-03-03 20:29:18 +00:00
init
This commit is contained in:
49
tests/fixtures/card.ts
vendored
Normal file
49
tests/fixtures/card.ts
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Card storage test fixtures with randomized personal data
|
||||
*/
|
||||
|
||||
import { faker } from '@faker-js/faker';
|
||||
import type { Card, CardCreateRequest, CardCreateWithUserKeyRequest } from '../../src/types';
|
||||
|
||||
/**
|
||||
* Generates a test card with randomized holder name
|
||||
* Card number is fixed to iyzico sandbox test card
|
||||
*/
|
||||
export function createTestCard(): Card {
|
||||
return {
|
||||
cardAlias: faker.helpers.arrayElement(['My Card', 'Personal Card', 'Main Card', 'Default Card']),
|
||||
cardNumber: '5528790000000008', // iyzico sandbox test card
|
||||
expireYear: '2030',
|
||||
expireMonth: '12',
|
||||
cardHolderName: faker.person.fullName(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a test card create request with randomized data
|
||||
*/
|
||||
export function createTestCardCreateRequest(): CardCreateRequest {
|
||||
return {
|
||||
locale: 'tr',
|
||||
conversationId: faker.string.uuid(),
|
||||
email: faker.internet.email().toLowerCase(),
|
||||
externalId: `external-${faker.string.alphanumeric(10)}`,
|
||||
card: createTestCard(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a test card create request with user key
|
||||
*/
|
||||
export function createCardCreateWithUserKeyRequest(cardUserKey: string): CardCreateWithUserKeyRequest {
|
||||
return {
|
||||
locale: 'tr',
|
||||
conversationId: faker.string.uuid(),
|
||||
cardUserKey,
|
||||
card: createTestCard(),
|
||||
};
|
||||
}
|
||||
|
||||
// Legacy exports for backward compatibility (static versions that generate once)
|
||||
export const testCard = createTestCard();
|
||||
export const testCardCreateRequest = createTestCardCreateRequest();
|
||||
206
tests/fixtures/payment.ts
vendored
Normal file
206
tests/fixtures/payment.ts
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
/**
|
||||
* Payment test fixtures with randomized personal data
|
||||
*/
|
||||
|
||||
import { faker } from '@faker-js/faker';
|
||||
import type {
|
||||
ThreeDSInitializeRequest,
|
||||
Non3DPaymentRequest,
|
||||
PaymentCard,
|
||||
Buyer,
|
||||
BillingAddress,
|
||||
ShippingAddress,
|
||||
BasketItem,
|
||||
} from '../../src/types';
|
||||
|
||||
/**
|
||||
* Generates a valid Turkish identity number (TC Kimlik No)
|
||||
* Uses a simple algorithm that produces valid-looking numbers
|
||||
*/
|
||||
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 random IP address
|
||||
*/
|
||||
function generateIpAddress(): string {
|
||||
return faker.internet.ipv4();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a test payment card with randomized holder name
|
||||
* Card number is fixed to iyzico sandbox test card
|
||||
*/
|
||||
export function createTestCard(): PaymentCard {
|
||||
return {
|
||||
cardHolderName: faker.person.fullName(),
|
||||
cardNumber: '5528790000000008', // iyzico sandbox test card
|
||||
expireMonth: '12',
|
||||
expireYear: '2030',
|
||||
cvc: '123',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a test buyer with randomized personal data
|
||||
*/
|
||||
export function createTestBuyer(): Buyer {
|
||||
const firstName = faker.person.firstName();
|
||||
const lastName = faker.person.lastName();
|
||||
|
||||
return {
|
||||
id: `BY${faker.string.alphanumeric(6).toUpperCase()}`,
|
||||
name: firstName,
|
||||
surname: lastName,
|
||||
identityNumber: generateTurkishIdentityNumber(),
|
||||
email: faker.internet.email({ firstName, lastName }).toLowerCase(),
|
||||
gsmNumber: generateTurkishPhoneNumber(),
|
||||
registrationAddress: `${faker.location.streetAddress()}, ${faker.location.city()}`,
|
||||
city: faker.location.city(),
|
||||
country: 'Turkey',
|
||||
ip: generateIpAddress(),
|
||||
zipCode: faker.location.zipCode('#####'),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a test billing address with randomized data
|
||||
*/
|
||||
export function createTestBillingAddress(): BillingAddress {
|
||||
return {
|
||||
contactName: faker.person.fullName(),
|
||||
city: faker.location.city(),
|
||||
country: 'Turkey',
|
||||
address: `${faker.location.streetAddress()}, ${faker.location.city()}`,
|
||||
zipCode: faker.location.zipCode('#####'),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a test shipping address with randomized data
|
||||
*/
|
||||
export function createTestShippingAddress(): ShippingAddress {
|
||||
return {
|
||||
contactName: faker.person.fullName(),
|
||||
city: faker.location.city(),
|
||||
country: 'Turkey',
|
||||
address: `${faker.location.streetAddress()}, ${faker.location.city()}`,
|
||||
zipCode: faker.location.zipCode('#####'),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates test basket items
|
||||
*/
|
||||
export function createTestBasketItems(): BasketItem[] {
|
||||
return [
|
||||
{
|
||||
id: `BI${faker.string.alphanumeric(3).toUpperCase()}`,
|
||||
name: faker.commerce.productName(),
|
||||
category1: faker.commerce.department(),
|
||||
category2: faker.commerce.productAdjective(),
|
||||
itemType: 'PHYSICAL',
|
||||
price: 0.3,
|
||||
},
|
||||
{
|
||||
id: `BI${faker.string.alphanumeric(3).toUpperCase()}`,
|
||||
name: faker.commerce.productName(),
|
||||
category1: 'Game',
|
||||
category2: 'Online Game Items',
|
||||
itemType: 'VIRTUAL',
|
||||
price: 0.5,
|
||||
},
|
||||
{
|
||||
id: `BI${faker.string.alphanumeric(3).toUpperCase()}`,
|
||||
name: faker.commerce.productName(),
|
||||
category1: 'Electronics',
|
||||
category2: faker.commerce.productAdjective(),
|
||||
itemType: 'PHYSICAL',
|
||||
price: 0.2,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a test 3DS initialize request with randomized data
|
||||
*/
|
||||
export function createTest3DSInitializeRequest(): ThreeDSInitializeRequest {
|
||||
return {
|
||||
locale: 'tr',
|
||||
conversationId: faker.string.uuid(),
|
||||
price: 1.0,
|
||||
paidPrice: 1.1,
|
||||
currency: 'TRY',
|
||||
installment: 1,
|
||||
paymentChannel: 'WEB',
|
||||
basketId: `B${faker.string.alphanumeric(5).toUpperCase()}`,
|
||||
paymentGroup: 'PRODUCT',
|
||||
callbackUrl: 'https://www.merchant.com/callback',
|
||||
paymentCard: createTestCard(),
|
||||
buyer: createTestBuyer(),
|
||||
billingAddress: createTestBillingAddress(),
|
||||
shippingAddress: createTestShippingAddress(),
|
||||
basketItems: createTestBasketItems(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a test non-3DS payment request with randomized data
|
||||
*/
|
||||
export function createTestNon3DPaymentRequest(): Non3DPaymentRequest {
|
||||
return {
|
||||
locale: 'tr',
|
||||
conversationId: faker.string.uuid(),
|
||||
price: 1.0,
|
||||
paidPrice: 1.1,
|
||||
currency: 'TRY',
|
||||
installment: 1,
|
||||
paymentChannel: 'WEB',
|
||||
basketId: `B${faker.string.alphanumeric(5).toUpperCase()}`,
|
||||
paymentGroup: 'PRODUCT',
|
||||
paymentCard: createTestCard(),
|
||||
buyer: createTestBuyer(),
|
||||
billingAddress: createTestBillingAddress(),
|
||||
shippingAddress: createTestShippingAddress(),
|
||||
basketItems: createTestBasketItems(),
|
||||
};
|
||||
}
|
||||
|
||||
// Legacy exports for backward compatibility (static versions that generate once)
|
||||
export const testCard = createTestCard();
|
||||
export const testBuyer = createTestBuyer();
|
||||
export const testBillingAddress = createTestBillingAddress();
|
||||
export const testShippingAddress = createTestShippingAddress();
|
||||
export const testBasketItems = createTestBasketItems();
|
||||
export const test3DSInitializeRequest = createTest3DSInitializeRequest();
|
||||
export const testNon3DPaymentRequest = createTestNon3DPaymentRequest();
|
||||
193
tests/fixtures/subscription.ts
vendored
Normal file
193
tests/fixtures/subscription.ts
vendored
Normal file
@@ -0,0 +1,193 @@
|
||||
/**
|
||||
* 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();
|
||||
Reference in New Issue
Block a user