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

chore(apps): Set app tokens #179

Merged
merged 21 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
5 changes: 5 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ jobs:
ECOM_AUTHENTICATION_ID: ${{ secrets.ECOM_AUTHENTICATION_ID }}
ECOM_API_KEY: ${{ secrets.ECOM_API_KEY }}
MERCADOPAGO_TOKEN: ${{ secrets.MERCADOPAGO_TOKEN }}
FRENET_TOKEN: ${{ secrets.FRENET_TOKEN }}
GALAXPAY_ID: ${{ secrets.GALAXPAY_ID }}
GALAXPAY_HASH: ${{ secrets.GALAXPAY_HASH }}
INFINITEPAY_ID: ${{ secrets.INFINITEPAY_ID }}
INFINITEPAY_SECRET: ${{ secrets.INFINITEPAY_SECRET }}
run: pnpm build

- name: Get npm global directories
Expand Down
64 changes: 64 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,38 @@ inputs:
description: 'App: Random token (https://randomkeygen.com/) to validate Datafrete webhooks'
mercadopago-token:
description: 'App: Mercadopago API access token'
frenet-token:
description: 'App: Frenet API token'
galaxpay-id:
description: 'App: Galax Pay ID'
galaxpay-hash:
description: 'App: Galax Pay hash'
ga-measurement-id:
description: 'App: Google Analytics API measurement id'
ga-api-token:
description: 'App: Google Analytics API secret'
infinitepay-id:
description: 'App: InifinitePay client ID'
infinitepay-secret:
description: 'App: InifinitePay client secret'
fb-pixel-id:
description: 'App: Facebook pixel ID'
fb-graph-token:
description: 'App: Facebook Graph token'
jadlog-contract-token:
description: 'App: Jadlog contract token'
pagarme-encrypt-key:
description: 'App: Pagar.me encryption Key'
pagarme-token:
description: 'App: Pagar.me API token'
paghiper-token:
description: 'App: PagHiper API token'
pix-credentials:
description: 'App: Pix credentials'
flashcourier-contract:
description: 'App: Flash Courier contract'
webhooks-token:
description: 'App: Webhooks token'

outputs: {}

Expand Down Expand Up @@ -166,6 +198,22 @@ runs:
GALAXPAY_PARTNER_HASH: ${{ inputs.galaxpay-partner-hash }}
DATAFRETE_OPERATOR_TOKEN: ${{ inputs.datafrete-operator-token }}
MERCADOPAGO_TOKEN: ${{ inputs.mercadopago-token }}
FRENET_TOKEN: ${{ inputs.frenet-token }}
GALAXPAY_ID: ${{ inputs.galaxpay-id }}
GALAXPAY_HASH: ${{ inputs.galaxpay-hash }}
GA_MEASUREMENT_ID: ${{ inputs.ga-measurement-id }}
GA_API_TOKEN: ${{ inputs.ga-api-token }}
INFINITEPAY_ID: ${{ inputs.infinitepay-id }}
INFINITEPAY_SECRET: ${{ inputs.infinitepay-secret }}
FB_PIXEL_ID: ${{ inputs.fb-pixel-id }}
FB_GRAPH_TOKEN: ${{ inputs.fb-graph-token }}
JADLOG_CONTRACT_TOKEN: ${{ inputs.jadlog-contract-token }}
PAGARME_ENCRYPT_KEY: ${{ inputs.pagarme-encrypt-key }}
PAGARME_TOKEN: ${{ inputs.pagarme-token }}
PAGHIPER_TOKEN: ${{ inputs.paghiper-token }}
PIX_CREDENTIALS: ${{ inputs.pix-credentials }}
FLASHCOURIER_CONTRACT: ${{ inputs.flashcourier-contract }}
WEBHOOKS_TOKEN: ${{ inputs.webhooks-token }}
run: |
export GAC_FILENAME=".gac-$RANDOM.json"
echo $FIREBASE_SERVICE_ACCOUNT > $GAC_FILENAME
Expand All @@ -189,6 +237,22 @@ runs:
GALAXPAY_PARTNER_HASH=$GALAXPAY_PARTNER_HASH
DATAFRETE_OPERATOR_TOKEN=$DATAFRETE_OPERATOR_TOKEN
MERCADOPAGO_TOKEN=$MERCADOPAGO_TOKEN
FRENET_TOKEN:$FRENET_TOKEN
GALAXPAY_ID=$GALAXPAY_ID
GALAXPAY_HASH=$GALAXPAY_HASH
GA_MEASUREMENT_ID=$GA_MEASUREMENT_ID
GA_API_TOKEN=$GA_API_TOKEN
INFINITEPAY_ID=$INFINITEPAY_ID
INFINITEPAY_SECRET=$INFINITEPAY_SECRET
FB_PIXEL_ID=$FB_PIXEL_ID
FB_GRAPH_TOKEN=$FB_GRAPH_TOKEN
JADLOG_CONTRACT_TOKEN=$JADLOG_CONTRACT_TOKEN
PAGARME_ENCRYPT_KEY=$PAGARME_ENCRYP_KEY
PAGARME_TOKEN=$PAGARME_TOKEN
PAGHIPER_TOKEN=$PAGHIPER_TOKEN
PIX_CREDENTIALS=$PIX_CREDENTIALS
FLASHCOURIER_CONTRACT=$FLASHCOURIER_CONTRACT
WEBHOOKS_TOKEN=$WEBHOOKS_TOKEN
" > functions/.env
if [ -z "$DEPLOY_CODEBASE" ]; then
GOOGLE_APPLICATION_CREDENTIALS=$GAC_FILENAME npm run deploy
Expand Down
27 changes: 21 additions & 6 deletions packages/apps/fb-conversions/src/fb-conversions-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,26 @@ const handleApiEvent: ApiEventHandler = async ({
}
logger.info(`> Webhook ${resourceId} [${evName}]`);

const fbPixelId = appData.fb_pixel_id;
const fbGraphToken = appData.fb_graph_token;
if (!process.env.FB_GRAPH_TOKEN) {
const fbGraphToken = appData.fb_graph_token;
if (typeof fbGraphToken === 'string' && fbGraphToken) {
process.env.FB_GRAPH_TOKEN = fbGraphToken;
} else {
logger.warn('Missing Facebook Graph token');
}
}

if (!process.env.FB_PIXEL_ID) {
const fbPixelId = appData.fb_pixel_id;
if (typeof fbPixelId === 'string' && fbPixelId) {
process.env.FB_PIXEL_ID = fbPixelId;
} else {
logger.warn('Missing Facebook pixel ID');
}
}

if (fbPixelId && fbGraphToken) {
FacebookAdsApi.init(fbGraphToken);
if (process.env.FB_PIXEL_ID && process.env.FB_GRAPH_TOKEN) {
FacebookAdsApi.init(process.env.FB_GRAPH_TOKEN);

if (evName === 'orders-new') {
const order = apiDoc as Orders;
Expand Down Expand Up @@ -119,7 +134,7 @@ const handleApiEvent: ApiEventHandler = async ({
);

const eventsData = [serverEvent];
const eventRequest = (new EventRequest(fbGraphToken, fbPixelId))
const eventRequest = (new EventRequest(process.env.FB_GRAPH_TOKEN, process.env.FB_PIXEL_ID))
.setEvents(eventsData);

try {
Expand Down Expand Up @@ -201,7 +216,7 @@ const handleApiEvent: ApiEventHandler = async ({
);

const eventsData = [serverEvent];
const eventRequest = (new EventRequest(fbGraphToken, fbPixelId))
const eventRequest = (new EventRequest(process.env.FB_GRAPH_TOKEN, process.env.FB_PIXEL_ID))
.setEvents(eventsData);

try {
Expand Down
16 changes: 15 additions & 1 deletion packages/apps/flash-courier/lib-mjs/calculate-flash-courier.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from 'axios';
import logger from 'firebase-functions/logger';

export default async ({ params, application }) => {
const appData = {
Expand All @@ -21,7 +22,20 @@ export default async ({ params, application }) => {
return response;
}

const flashcourierKey = appData.flashcourier_contract && appData.flashcourier_contract.key;
let flashcourierKey;

if (process.env.FLASHCOURIER_CONTRACT) {
try {
const contract = JSON.parse(process.env.FLASHCOURIER_CONTRACT);
flashcourierKey = contract.key;
} catch (e) {
logger.error(e);
flashcourierKey = appData.flashcourier_contract && appData.flashcourier_contract.key;
}
} else {
flashcourierKey = appData.flashcourier_contract && appData.flashcourier_contract.key;
}

if (!flashcourierKey) {
return {
status: 409,
Expand Down
13 changes: 12 additions & 1 deletion packages/apps/flash-courier/lib-mjs/update-tracking.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@ export default () => {
}

if (appData) {
const contract = appData.flashcourier_contract;
let contract;
if (process.env.FLASHCOURIER_CONTRACT) {
try {
contract = JSON.parse(process.env.FLASHCOURIER_CONTRACT);
} catch (e) {
logger.error(e);
contract = appData.flashcourier_contract;
}
} else {
contract = appData.flashcourier_contract;
}

if (contract) {
const {
login,
Expand Down
3 changes: 2 additions & 1 deletion packages/apps/flash-courier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"dependencies": {
"@cloudcommerce/api": "workspace:*",
"@cloudcommerce/firebase": "workspace:*",
"axios": "^1.4.0"
"axios": "^1.4.0",
"firebase-functions": "^4.4.1"
},
"devDependencies": {
"@cloudcommerce/types": "workspace:*"
Expand Down
19 changes: 13 additions & 6 deletions packages/apps/frenet/lib-mjs/calculate-frenet.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from 'axios';
import logger from 'firebase-functions/logger';

const getDimension = (side, item) => {
if (item.dimensions && item.dimensions[side]) {
Expand All @@ -23,11 +24,17 @@ export default async ({ params, application }) => {
...application.hidden_data,
};

if (!config.frenet_access_token) {
return {
error: 'FRENET_ERR',
message: 'Frenet token is unset on app hidden data (calculate unavailable) for this store',
};
if (!process.env.FRENET_TOKEN) {
const frenetToken = config.frenet_access_token;
if (typeof frenetToken === 'string' && frenetToken) {
process.env.FRENET_TOKEN = frenetToken;
} else {
logger.warn('Missing Frenet token');
return {
error: 'FRENET_ERR',
message: 'Frenet token is unset on app hidden data (calculate unavailable) for this store',
};
}
}

// https://apx-mods.e-com.plus/api/v1/calculate_shipping/response_schema.json?store_id=100
Expand Down Expand Up @@ -87,7 +94,7 @@ export default async ({ params, application }) => {
method: 'post',
headers: {
'Content-Type': 'application/json',
token: config.frenet_access_token,
token: process.env.FRENET_TOKEN,
},
data: schema,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,28 @@ const handleApiEvent: ApiEventHandler = async ({
return null;
}
logger.info(`> Webhook ${resourceId} [${evName}] => ${apiDoc}`);

if (!process.env.GALAXPAY_ID) {
const galaxpayId = appData.galaxpay_id;
if (typeof galaxpayId === 'string' && galaxpayId) {
process.env.GALAXPAY_ID = galaxpayId;
} else {
logger.warn('Missing GalaxPay ID');
}
}

if (!process.env.GALAXPAY_HASH) {
const galaxpayHash = appData.galaxpay_hash;
if (typeof galaxpayHash === 'string' && galaxpayHash) {
process.env.GALAXPAY_HASH = galaxpayHash;
} else {
logger.warn('Missing GalaxPay Hash');
}
}

const galaxpayAxios = new GalaxpayAxios({
galaxpayId: appData.galaxpay_id,
galaxpayHash: appData.galaxpay_hash,
galaxpayId: process.env.GALAXPAY_ID,
galaxpayHash: process.env.GALAXPAY_HASH,
});

await galaxpayAxios.preparing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const { GALAXPAY_PARTNER_ID, GALAXPAY_PARTNER_HASH } = process.env;
const firestoreColl = 'galaxpayTokens';

type Option = {
galaxpayId: string;
galaxpayHash: string;
galaxpayId?: string;
galaxpayHash?: string;
}

export default class GalaxPay {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Orders, Applications } from '@cloudcommerce/types';
import logger from 'firebase-functions/logger';
import GalaxpayAxios from './auth/create-access';

const checkAmountItemsOrder = (
Expand Down Expand Up @@ -47,10 +48,28 @@ const updateValueSubscription = (
) => {
const value = checkAmountItemsOrder({ ...amount }, [...items], { ...plan });

if (!process.env.GALAXPAY_ID) {
const galaxpayId = appData.hidden_data?.galaxpay_id;
if (typeof galaxpayId === 'string' && galaxpayId) {
process.env.GALAXPAY_ID = galaxpayId;
} else {
logger.warn('Missing GalaxPay ID');
}
}

if (!process.env.GALAXPAY_HASH) {
const galaxpayHash = appData.hidden_data?.galaxpay_hash;
if (typeof galaxpayHash === 'string' && galaxpayHash) {
process.env.GALAXPAY_HASH = galaxpayHash;
} else {
logger.warn('Missing GalaxPay ID');
}
}

return new Promise((resolve, reject) => {
const galaxpayAxios = new GalaxpayAxios({
galaxpayId: appData.hidden_data?.galaxpay_id,
galaxpayHash: appData.hidden_data?.galaxpay_hash,
galaxpayId: process.env.GALAXPAY_ID,
galaxpayHash: process.env.GALAXPAY_HASH,
});

galaxpayAxios.preparing
Expand Down
21 changes: 19 additions & 2 deletions packages/apps/galaxpay/src/functions-lib/galaxpay/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,27 @@ const handleWehook = async (req: Request, res: Response) => {

try {
// check subscription and transaction status before in galaxpay
if (!process.env.GALAXPAY_ID) {
const galaxpayId = app.hidden_data?.galaxpay_id;
if (typeof galaxpayId === 'string' && galaxpayId) {
process.env.GALAXPAY_ID = galaxpayId;
} else {
logger.warn('Missing GalaxPay ID');
}
}

if (!process.env.GALAXPAY_HASH) {
const galaxpayHash = app.hidden_data?.galaxpay_hash;
if (typeof galaxpayHash === 'string' && galaxpayHash) {
process.env.GALAXPAY_HASH = galaxpayHash;
} else {
logger.warn('Missing GalaxPay Hash');
}
}

const galaxpayAxios = new GalaxpayAxios({
galaxpayId: app.hidden_data?.galaxpay_id,
galaxpayHash: app.hidden_data?.galaxpay_hash,
galaxpayId: process.env.GALAXPAY_ID,
galaxpayHash: process.env.GALAXPAY_HASH,
});
await galaxpayAxios.preparing;

Expand Down
21 changes: 19 additions & 2 deletions packages/apps/galaxpay/src/galaxpay-create-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,27 @@ export default async (appData: AppModuleBody) => {
amount: amount.total,
};

if (!process.env.GALAXPAY_ID) {
const galaxpayId = configApp.galaxpay_id;
if (typeof galaxpayId === 'string' && galaxpayId) {
process.env.GALAXPAY_ID = galaxpayId;
} else {
logger.warn('Missing GalaxPay ID');
}
}

if (!process.env.GALAXPAY_HASH) {
const galaxpayHash = configApp.galaxpay_hash;
if (typeof galaxpayHash === 'string' && galaxpayHash) {
process.env.GALAXPAY_HASH = galaxpayHash;
} else {
logger.warn('Missing GalaxPay Hash');
}
}
// setup required `transaction` response object
const galaxpayAxios = new Galaxpay({
galaxpayId: configApp.galaxpay_id,
galaxpayHash: configApp.galaxpay_hash,
galaxpayId: process.env.GALAXPAY_ID,
galaxpayHash: process.env.GALAXPAY_HASH,
});

// indicates whether the buyer should be redirected to payment link right after checkout
Expand Down
Loading
Loading