Integrate payment checking and recording of access rights updates
The test address used to check the functionality is ommitted from this commit
If you wish to perform tests at this point, use your own
Simon Volpert
3 years ago
208 | 208 | # First request to access file by this client |
209 | 209 | if access_index == -1: |
210 | 210 | # Create an invoice |
211 | record = [request_file.name, 'invoice', 'bitcoin cash address', '0.0', datetime.datetime.now().isoformat(' ', timespec='seconds')] | |
211 | balance = get_balance(test_address) | |
212 | record = [request_file.name, 'invoice', test_address, str(balance), datetime.datetime.now().isoformat(' ', timespec='seconds')] | |
212 | 213 | access_data.append(record) |
213 | 214 | write_access_data() |
214 | 215 | # Show payment request page |
215 | 216 | show_invoice() |
216 | 217 | raise SystemExit |
217 | 218 | # Second request to access file by this client |
218 | elif len(record) > 1 and record[0] != 'paid': | |
219 | elif len(record) > 1 and record[1] != 'paid': | |
220 | balance = float(record[3]) | |
221 | new_balance = get_balance(record[2]) | |
222 | if new_balance < balance + default_price: | |
223 | record[4] = datetime.datetime.now().isoformat(' ', timespec='seconds') | |
224 | write_access_data() | |
225 | show_invoice() | |
226 | raise SystemExit | |
219 | 227 | # Mark payment as received |
220 | 228 | record[1] = 'paid' |
221 | for num, line in enumerate(access_data): | |
222 | access_file[num] = ' '.join(line) | |
223 | write_state(cert_hash, access_file) | |
229 | record[3] = str(new_balance - balance) | |
230 | write_access_data() | |
224 | 231 | # Give the client their file |
225 | 232 | if len(record) > 1 and record[1] == 'paid': |
226 | 233 | # Patch mime type definitions with Gemini-specific types |