payment started

This commit is contained in:
Steve Waterworth
2018-01-25 17:42:38 +00:00
parent 5539d06bb5
commit 0dc55b878d
8 changed files with 74 additions and 2 deletions

View File

@@ -63,6 +63,14 @@ services:
- "8080"
networks:
- robot-shop
payment:
build:
context: payment
image: steveww/rs-payment
ports:
- "8080"
networks:
- robot-shop
web:
build:
context: web
@@ -71,6 +79,7 @@ services:
- catalogue
- user
- shipping
- payment
ports:
- "8080:8080"
networks:

13
payment/Dockerfile Normal file
View File

@@ -0,0 +1,13 @@
FROM python:3
EXPOSE 8080
WORKDIR /app
COPY requirements.txt /app/
RUN pip install -r requirements.txt
COPY payment.py /app/
CMD ["python", "payment.py"]

34
payment/payment.py Normal file
View File

@@ -0,0 +1,34 @@
import os
import sys
import logging
import requests
from flask import Flask
from flask import request
app = Flask(__name__)
@app.route('/health', methods=['GET'])
def health():
return 'OK'
@app.route('/pay/<id>', methods=['POST'])
def pay(id):
app.logger.info('payment for {}'.format(id))
cart = request.get_json()
app.logger.info(cart)
# dummy call to Paypal, hope they dont object
req = requests.get('https://paypal.com/')
app.logger.info('paypal returned {}'.format(req.status_code))
# TDOD - order history
return 'OK'
if __name__ == "__main__":
sh = logging.StreamHandler(sys.stdout)
sh.setLevel(logging.INFO)
app.logger.addHandler(sh)
app.logger.setLevel(logging.INFO)
port = int(os.getenv("PAYMENT_PORT", "8080"))
app.run(host='0.0.0.0', port=port)

3
payment/requirements.txt Normal file
View File

@@ -0,0 +1,3 @@
Flask
requests
instana

View File

@@ -58,6 +58,10 @@ server {
proxy_pass http://shipping:8080/;
}
location /api/payment/ {
proxy_pass http://payment:8080/;
}
location /nginx_status {
stub_status on;
access_log off;

View File

@@ -21,7 +21,7 @@
</tr>
<tr>
<td>&nbsp;</td>
<td>Tax</td>
<td>Inc Tax</td>
<td class="currency">&euro;{{ data.cart.tax.toFixed(2) }}</td>
</tr>
<tr>

View File

@@ -320,6 +320,15 @@
$scope.data.cart = currentUser.cart;
$scope.pay = function() {
$http({
url: '/api/payment/pay/' + $scope.data.uniqueid,
method: 'POST',
data: $scope.data.cart
}).then((res) => {
console.log('payment ok');
}).catch((e) => {
console.log('ERROR', e);
});
};
console.log('paymentform init');

View File

@@ -21,7 +21,7 @@
</tr>
<tr>
<td>&nbsp;</td>
<td>Tax</td>
<td>Inc Tax</td>
<td class="currency">&euro;{{ data.cart.tax.toFixed(2) }}</td>
</tr>
<tr>