Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use demo response #8

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 0 additions & 87 deletions app/__tests__/aggregator.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const axios = require('axios');
const Aggregator = require('../services/aggregators/aggregator');
const { BadRequestError } = require('../utils/errorUtils');

jest.mock('axios');

Expand Down Expand Up @@ -97,92 +96,6 @@ describe('Aggregator Instance', () => {
expect(response).toEqual(pgResponse.data.payment_url);
});

test('createOrder fail', async () => {
const requestPayload = {
customer_name: 'Customer Name',
customer_email: '[email protected]',
app_id: '000000000000000000000001',
company_id: '1',
customer_contact: '8888888888',
gid: 'TR662637B30D570001',
fynd_platform_id: 'FY662A607D0EC6524BEA',
g_user_id: '65fc3a26b7e85bd44752641a',
amount: 100000,
currency: 'INR',
merchant_locale: 'en',
locale: 'en',
mode: 'live',
journey_type: 'forward',
payment_methods: [
{
code: 'DUMMY',
name: 'DUMMY',
sub_payment_mode: [],
},
],
success_url:
'https://fynd.com/cart/order-status?success=true&status=complete&order_id=FY662A607D0EC6524BEA&aggregator_name=Dummy&cart_id=662a5d614d4cd74ae13afe36',
cancel_url:
'https://fynd.com/cart/order-status?success=false&status=failed&order_id=FY662A607D0EC6524BEA&aggregator_name=Dummy&cart_id=662a5d614d4cd74ae13afe36',
billing_address: {
area: 'Bengalur',
city: 'Bangalore',
name: 'Customer name',
email: '[email protected]',
phone: '8888888888',
state: 'Karnataka',
address: 'Bengalur',
country: 'India',
pincode: '560077',
landmark: 'Bengalur',
area_code: '560077',
pos_state: 'Karnataka',
address_id: 3535,
address_type: 'home',
area_code_slug: '560077',
country_iso_code: 'IN',
country_phone_code: '+91',
g_address_id: 'None',
},
shipping_address: {
area: 'Bengalur',
city: 'Bangalore',
name: 'Customer name',
email: '[email protected]',
phone: '8888888888',
state: 'Karnataka',
address: 'Bengalur',
country: 'India',
pincode: '560077',
landmark: 'Bengalur',
area_code: '560077',
pos_state: 'Karnataka',
address_id: 3535,
address_type: 'home',
area_code_slug: '560077',
country_iso_code: 'IN',
country_phone_code: '+91',
g_address_id: 'None',
},
kind: 'sale',
initiated_at: 1714053246,
cod_eligibility: true,
meta: {},
};
const pgResponse = {
status: 400,
data: {
payment_url: 'https://pg-url.com/payments/payment_id_001',
},
};

axios.post.mockResolvedValue(pgResponse);

await expect(async () => {
await aggregator.createOrder(requestPayload);
}).rejects.toThrow(BadRequestError);
});

test('processCallback', async () => {
const callbackPayload = {
amount: 33.0,
Expand Down
69 changes: 36 additions & 33 deletions app/services/aggregators/aggregator.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,43 @@ class Aggregator {
Returns: redirect_url for payment page
*/

const customerData = {
customer_name: payload.customer_name,
customer_contact: payload.customer_contact,
customer_email: payload.customer_email,
};
const callbackUrl = `${config.base_url}api/v1/callback/${this.companyId}/${this.appId}`;

const body = {
// Create payment gateway specific body here
amount: payload.amount,
currency: payload.currency,
transactionReferenceId: payload.gid,
customer: customerData,
callbackUrl,
address: payload.billing_address,
};

const url = config.pgBaseUrl + aggregatorConfig.createOrder;

const headers = {
ContentType: 'application/json',
};

const response = await axios.post({
method: 'POST',
url,
data: body,
headers,
});
// const customerData = {
// customer_name: payload.customer_name,
// customer_contact: payload.customer_contact,
// customer_email: payload.customer_email,
// };
// const callbackUrl = `${config.base_url}api/v1/callback/${this.companyId}/${this.appId}`;

// const body = {
// // Create payment gateway specific body here
// amount: payload.amount,
// currency: payload.currency,
// transactionReferenceId: payload.gid,
// customer: customerData,
// callbackUrl,
// address: payload.billing_address,
// };

// const url = config.pgBaseUrl + aggregatorConfig.createOrder;

// const headers = {
// ContentType: 'application/json',
// };

// const response = await axios.post({
// method: 'POST',
// url,
// data: body,
// headers,
// });
// Demo response from payment gateway
// const response = {
// status: 200,
// payment_url: "https://api.razorpay.com/accept-payment/pay_id_1234567890/"
// }
const response = {
status: 200,
data: {
...payload,
payment_url: 'https://pg-url.com/payments/payment_id_001',
},
};

if (response.status === 200) {
return response.data.payment_url;
Expand Down
Loading