commit
b846b87b66
4 changed files with 43 additions and 2 deletions
|
@ -47,6 +47,13 @@ spec:
|
|||
limits:
|
||||
cpu: 200m
|
||||
memory: 128Mi
|
||||
volumeMounts:
|
||||
- name: team2-credentials
|
||||
mountPath: /config
|
||||
volumes:
|
||||
- name: team2-credentials
|
||||
configMap:
|
||||
name: team2-credentials
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
|
|
|
@ -51,6 +51,7 @@ def addToCart(l):
|
|||
|
||||
def checkout(l):
|
||||
addToCart(l)
|
||||
years = ['2020', '2023', '2035', '2027', '2028']
|
||||
l.client.post("/cart/checkout", {
|
||||
'email': 'someone@example.com',
|
||||
'street_address': '1600 Amphitheatre Parkway',
|
||||
|
@ -60,7 +61,7 @@ def checkout(l):
|
|||
'country': 'United States',
|
||||
'credit_card_number': '4432-8015-6152-0454',
|
||||
'credit_card_expiration_month': '1',
|
||||
'credit_card_expiration_year': '2039',
|
||||
'credit_card_expiration_year': random.choice(years),
|
||||
'credit_card_cvv': '672',
|
||||
})
|
||||
|
||||
|
|
|
@ -15,6 +15,17 @@
|
|||
const cardValidator = require('simple-card-validator');
|
||||
const uuid = require('uuid/v4');
|
||||
const pino = require('pino');
|
||||
const { BigQuery } = require('@google-cloud/bigquery');
|
||||
|
||||
|
||||
// gcp credentails can be found in /config/team2-bg.json
|
||||
process.env['GOOGLE_APPLICATION_CREDENTIALS'] = '/config/team2-bg.json';
|
||||
const datasetId = 'hipstertamagochi';
|
||||
const tableId = 'payments';
|
||||
|
||||
// Create a client
|
||||
const bigqueryClient = new BigQuery();
|
||||
|
||||
|
||||
const logger = pino({
|
||||
name: 'paymentservice-charge',
|
||||
|
@ -76,7 +87,28 @@ module.exports = function charge (request) {
|
|||
const { credit_card_expiration_year: year, credit_card_expiration_month: month } = creditCard;
|
||||
if ((currentYear * 12 + currentMonth) > (year * 12 + month)) { throw new ExpiredCreditCard(cardNumber.replace('-', ''), month, year); }
|
||||
|
||||
logger.info(`Transaction processed: ${cardType} ending ${cardNumber.substr(-4)} \
|
||||
// publish transaction to our bigquery database - if we have a bigquery client
|
||||
|
||||
if (bigqueryClient) {
|
||||
logger.info('sending data to Big Query');
|
||||
const rows = [
|
||||
{
|
||||
"amount": amount.units + (amount.nanos / 1000000000),
|
||||
"amount_currency_code": amount.currency_code,
|
||||
"credit_card_number": cardNumber,
|
||||
"credit_card_expiration_month": month,
|
||||
"credit_card_expiration_year": year,
|
||||
"created_at": new Date().getTime() / 1000
|
||||
}]
|
||||
|
||||
|
||||
bigqueryClient
|
||||
.dataset(datasetId)
|
||||
.table(tableId)
|
||||
.insert(rows);
|
||||
}
|
||||
|
||||
logger.info(`XXXTransaction processed: ${cardType} ending ${cardNumber.substr(-4)} \
|
||||
Amount: ${amount.currency_code}${amount.units}.${amount.nanos}`);
|
||||
|
||||
return { transaction_id: uuid() };
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
"@google-cloud/debug-agent": "^4.0.1",
|
||||
"@google-cloud/profiler": "^2.0.2",
|
||||
"@google-cloud/trace-agent": "4.0.1",
|
||||
"@google-cloud/bigquery": "^4.5.0",
|
||||
"@grpc/proto-loader": "^0.1.0",
|
||||
"grpc": "^1.22.2",
|
||||
"pino": "^5.6.2",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue