Skip to content
Open
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
20 changes: 19 additions & 1 deletion assets/IPOSPayIntegration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,22 @@ def charge_token(self, merchant_id, payment_token_id, amount, currency="USD", me
response.raise_for_status()
return response.json()

End of IPOSPayIntegration.py.
def charge_ach(self, merchant_id, ach_token_id, amount, currency="USD", metadata={}):
"""Process an ACH transaction using a token from the order form."""
url = f"{self.base_url}/charge_ach"
headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json"
}
payload = {
"merchant_id": merchant_id,
"ach_token_id": ach_token_id,
"amount": amount,
"currency": currency,
"metadata": metadata
}
response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
return response.json()

# End of IPOSPayIntegration.py.
11 changes: 9 additions & 2 deletions assets/app_final.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,30 @@
def charge():
try:
data = request.json
required_fields = ['merchant_id', 'payment_token_id', 'amount']
required_fields = ['merchant_id', 'payment_token_id', 'amount', 'payment_method', 'shipping_zip']
for field in required_fields:
if field not in data:
return jsonify({"error": f"Missing required field: {field}"}), 400

merchant_id = data['merchant_id']
payment_token_id = data['payment_token_id']
amount = data['amount']
payment_method = data['payment_method']
shipping_zip = data['shipping_zip']
currency = data.get('currency', 'USD')
metadata = data.get('metadata', {})
metadata['shipping_zip'] = shipping_zip
metadata['payment_method'] = payment_method

# Improved domain detection
domain = request.headers.get("Host", socket.gethostname())
domain = domain.split(":")[0] # Strip port if present

ipos = IPOSPayIntegration(domain)
response = ipos.charge_token(merchant_id, payment_token_id, amount, currency, metadata)
if payment_method.lower() == 'ach':
response = ipos.charge_ach(merchant_id, payment_token_id, amount, currency, metadata)
else:
response = ipos.charge_token(merchant_id, payment_token_id, amount, currency, metadata)

return jsonify(response), 200

Expand Down
30 changes: 27 additions & 3 deletions html/order.smrtpayments.com/public_html/order.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,33 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SMRT Order Form</title>
<link rel="stylesheet" href="/assets/custom.css">
</head>
<body>
<h1>Order Form Coming Soon</h1>
<p>The full order form will be live shortly. Please check back soon.</p>
<h1>SMRT Order Form</h1>
<form id="order-form">
<label for="amount">Order Amount ($):</label>
<input type="number" id="amount" required step="0.01">
<br>
<label for="shipping-zip">Shipping ZIP/Postal Code:</label>
<input type="text" id="shipping-zip" required>
<br>
<label for="payment-method">Payment Method:</label>
<select id="payment-method">
<option value="credit">Credit Card</option>
<option value="ach">ACH</option>
</select>
<br>
<label for="payment-token">Payment Token:</label>
<input type="text" id="payment-token" required>
<br>
<div>
Shipping: $<span id="shipping-cost">0.00</span><br>
Surcharge: $<span id="surcharge">0.00</span><br>
<strong>Total: $<span id="total-cost">0.00</span></strong>
</div>
<button type="submit">Submit Order</button>
</form>
<script src="order.js"></script>
</body>
</html>
</html>
61 changes: 59 additions & 2 deletions html/order.smrtpayments.com/public_html/order.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,59 @@
// Placeholder JS for SMRT Order Form
console.log("Order form script loaded. Full functionality coming soon.");
document.addEventListener('DOMContentLoaded', () => {
const form = document.getElementById('order-form');
const shippingCostSpan = document.getElementById('shipping-cost');
const surchargeSpan = document.getElementById('surcharge');
const totalCostSpan = document.getElementById('total-cost');

function lookupShipping(zip) {
if (!zip) return 0;
if (zip.startsWith('3')) return 35;
if (zip.startsWith('9')) return 60;
return 45;
}

function updateTotals() {
const amount = parseFloat(document.getElementById('amount').value) || 0;
const zip = document.getElementById('shipping-zip').value;
const method = document.getElementById('payment-method').value;
const shipping = lookupShipping(zip);
const subtotal = amount + shipping;
let surcharge = 0;
if (method === 'credit') {
surcharge = subtotal * 0.04;
}
const total = subtotal + surcharge;
shippingCostSpan.textContent = shipping.toFixed(2);
surchargeSpan.textContent = surcharge.toFixed(2);
totalCostSpan.textContent = total.toFixed(2);
return { shipping, surcharge, total };
}

document.getElementById('shipping-zip').addEventListener('input', updateTotals);
document.getElementById('payment-method').addEventListener('change', updateTotals);
document.getElementById('amount').addEventListener('input', updateTotals);

form.addEventListener('submit', async (e) => {
e.preventDefault();
const { shipping, surcharge, total } = updateTotals();
const data = {
merchant_id: 'ORDER_MERCHANT',
payment_token_id: document.getElementById('payment-token').value,
amount: total,
currency: 'USD',
payment_method: document.getElementById('payment-method').value,
shipping_zip: document.getElementById('shipping-zip').value,
metadata: { shipping_cost: shipping, surcharge }
};
try {
const resp = await fetch('/charge', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
const result = await resp.json();
alert('Payment result: ' + JSON.stringify(result));
} catch (err) {
alert('Payment failed: ' + err.message);
}
});
});
11 changes: 9 additions & 2 deletions webserv_deploy/app_final.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,30 @@
def charge():
try:
data = request.json
required_fields = ['merchant_id', 'payment_token_id', 'amount']
required_fields = ['merchant_id', 'payment_token_id', 'amount', 'payment_method', 'shipping_zip']
for field in required_fields:
if field not in data:
return jsonify({"error": f"Missing required field: {field}"}), 400

merchant_id = data['merchant_id']
payment_token_id = data['payment_token_id']
amount = data['amount']
payment_method = data['payment_method']
shipping_zip = data['shipping_zip']
currency = data.get('currency', 'USD')
metadata = data.get('metadata', {})
metadata['shipping_zip'] = shipping_zip
metadata['payment_method'] = payment_method

# Improved domain detection
domain = request.headers.get("Host", socket.gethostname())
domain = domain.split(":")[0] # Strip port if present

ipos = IPOSPayIntegration(domain)
response = ipos.charge_token(merchant_id, payment_token_id, amount, currency, metadata)
if payment_method.lower() == 'ach':
response = ipos.charge_ach(merchant_id, payment_token_id, amount, currency, metadata)
else:
response = ipos.charge_token(merchant_id, payment_token_id, amount, currency, metadata)

return jsonify(response), 200

Expand Down
20 changes: 19 additions & 1 deletion webserv_deploy/webserv_deploy/IPOSPayIntegration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,22 @@ def charge_token(self, merchant_id, payment_token_id, amount, currency="USD", me
response.raise_for_status()
return response.json()

End of IPOSPayIntegration.py.
def charge_ach(self, merchant_id, ach_token_id, amount, currency="USD", metadata={}):
"""Process an ACH transaction using a token from the order form."""
url = f"{self.base_url}/charge_ach"
headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json"
}
payload = {
"merchant_id": merchant_id,
"ach_token_id": ach_token_id,
"amount": amount,
"currency": currency,
"metadata": metadata
}
response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
return response.json()

# End of IPOSPayIntegration.py.
11 changes: 9 additions & 2 deletions webserv_deploy/webserv_deploy/app_final.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,30 @@
def charge():
try:
data = request.json
required_fields = ['merchant_id', 'payment_token_id', 'amount']
required_fields = ['merchant_id', 'payment_token_id', 'amount', 'payment_method', 'shipping_zip']
for field in required_fields:
if field not in data:
return jsonify({"error": f"Missing required field: {field}"}), 400

merchant_id = data['merchant_id']
payment_token_id = data['payment_token_id']
amount = data['amount']
payment_method = data['payment_method']
shipping_zip = data['shipping_zip']
currency = data.get('currency', 'USD')
metadata = data.get('metadata', {})
metadata['shipping_zip'] = shipping_zip
metadata['payment_method'] = payment_method

# Improved domain detection
domain = request.headers.get("Host", socket.gethostname())
domain = domain.split(":")[0] # Strip port if present

ipos = IPOSPayIntegration(domain)
response = ipos.charge_token(merchant_id, payment_token_id, amount, currency, metadata)
if payment_method.lower() == 'ach':
response = ipos.charge_ach(merchant_id, payment_token_id, amount, currency, metadata)
else:
response = ipos.charge_token(merchant_id, payment_token_id, amount, currency, metadata)

return jsonify(response), 200

Expand Down