Merge pull request #8 from jazzm0/publish_payments

Publish payments
This commit is contained in:
tobiastraxel 2019-12-11 11:01:23 +01:00 committed by GitHub
commit b846b87b66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 2 deletions

View file

@ -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

View file

@ -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',
})

View file

@ -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() };

View file

@ -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",