0002-misc-add-cli-tool-for-testing-48064.patch
README.txt | ||
---|---|---|
69 | 69 | |
70 | 70 |
Options: |
71 | 71 |
--help Show this message and exit. |
72 | ||
73 | ||
74 |
Generic CLI Tool |
|
75 |
================ |
|
76 | ||
77 |
You can put some configuration in ~/.config/eopayment.init :: |
|
78 | ||
79 |
[misc] |
|
80 |
debug=yes |
|
81 | ||
82 |
[systempayv2] |
|
83 |
# same name as passed in the options argument to Payment.__init__() |
|
84 |
vads_site_id=12345678 |
|
85 |
secret_test=xyzabcdefgh |
|
86 |
vads_ctx_mode=TEST |
|
87 | ||
88 |
$ python3 -m eopayment --option vads_site_id=56781234 request 10.0 --param transaction_id=1234 --param email=john.doe@example.com |
|
89 |
Transaction ID: 1234 |
|
90 |
<form method="POST" action="https://paiement.systempay.fr/vads-payment/"> |
|
91 |
<input type="hidden" name="vads_cust_country" value="FR"/> |
|
92 |
<input type="hidden" name="vads_validation_mode" value=""/> |
|
93 |
<input type="hidden" name="vads_site_id" value="51438584"/> |
|
94 |
<input type="hidden" name="vads_payment_config" value="SINGLE"/> |
|
95 |
<input type="hidden" name="vads_trans_id" value="GavPXW"/> |
|
96 |
<input type="hidden" name="vads_action_mode" value="INTERACTIVE"/> |
|
97 |
<input type="hidden" name="vads_contrib" value="eopayment"/> |
|
98 |
<input type="hidden" name="vads_page_action" value="PAYMENT"/> |
|
99 |
<input type="hidden" name="vads_amount" value="1010"/> |
|
100 |
<input type="hidden" name="signature" value="d5690d02fed621687b19c90053a77b37a1c78370"/> |
|
101 |
<input type="hidden" name="vads_ctx_mode" value="TEST"/> |
|
102 |
<input type="hidden" name="vads_version" value="V2"/> |
|
103 |
<input type="hidden" name="vads_payment_cards" value=""/> |
|
104 |
<input type="hidden" name="vads_ext_info_eopayment_trans_id" value="1234"/> |
|
105 |
<input type="hidden" name="vads_trans_date" value="20201027211254"/> |
|
106 |
<input type="hidden" name="vads_language" value="fr"/> |
|
107 |
<input type="hidden" name="vads_capture_delay" value=""/> |
|
108 |
<input type="hidden" name="vads_currency" value="978"/> |
|
109 |
<input type="hidden" name="vads_cust_email" value="john.doe@example.com"/> |
|
110 |
<input type="hidden" name="vads_return_mode" value="GET"/> |
|
111 |
<input type="submit" name="Submit" value="Submit" /> |
|
112 |
</form> |
|
113 |
[ Local browser is automatically opened with this form which is auto-submitted ] |
eopayment/__main__.py | ||
---|---|---|
1 |
# eopayment - online payment library |
|
2 |
# Copyright (C) 2011-2020 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software: you can redistribute it and/or modify it |
|
5 |
# under the terms of the GNU Affero General Public License as published |
|
6 |
# by the Free Software Foundation, either version 3 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU Affero General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU Affero General Public License |
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 |
from __future__ import print_function |
|
18 | ||
19 |
import configparser |
|
20 |
import decimal |
|
21 |
import logging |
|
22 |
import os.path |
|
23 |
import subprocess |
|
24 |
import tempfile |
|
25 | ||
26 |
import click |
|
27 | ||
28 |
from . import Payment, FORM, URL |
|
29 | ||
30 | ||
31 |
def option(value): |
|
32 |
try: |
|
33 |
name, value = value.split('=', 1) |
|
34 |
except Exception: |
|
35 |
raise ValueError('invalid option %s' % value) |
|
36 |
return (name, value) |
|
37 | ||
38 | ||
39 |
@click.group() |
|
40 |
@click.argument('backend', type=str) |
|
41 |
@click.option('--option', type=option, multiple=True) |
|
42 |
@click.option('--debug/--no-debug', default=None) |
|
43 |
@click.pass_context |
|
44 |
def main(ctx, backend, debug, option): |
|
45 |
config_file = os.path.expanduser('~/.config/eopayment.ini') |
|
46 |
option = list(option) |
|
47 |
if os.path.exists(config_file): |
|
48 |
parser = configparser.ConfigParser(interpolation=None) |
|
49 |
with open(config_file) as fd: |
|
50 |
parser.read_file(fd) |
|
51 |
if debug is None: |
|
52 |
debug = parser.getboolean('misc', 'debug', fallback=False) |
|
53 |
if parser.has_section(backend): |
|
54 |
option.extend(parser.items(section=backend)) |
|
55 |
if debug: |
|
56 |
logging.basicConfig(level=logging.DEBUG) |
|
57 |
ctx.obj = Payment(backend, dict(option)) |
|
58 | ||
59 | ||
60 |
@main.command() |
|
61 |
@click.argument('amount', type=decimal.Decimal) |
|
62 |
@click.option('--param', type=option, multiple=True) |
|
63 |
@click.pass_obj |
|
64 |
def request(backend, amount, param): |
|
65 |
transaction_id, kind, what = backend.request(amount, **dict(param)) |
|
66 |
print('Transaction ID:', transaction_id) |
|
67 |
if kind == FORM: |
|
68 |
print(what) |
|
69 |
with tempfile.NamedTemporaryFile(mode='w', delete=False) as fd: |
|
70 |
print(what, file=fd) |
|
71 |
print('''<script>document.getElementsByName('Submit')[0].click()</script>''', file=fd) |
|
72 |
subprocess.call(['gnome-www-browser', fd.name]) |
|
73 |
elif kind == URL: |
|
74 |
print('Please click on URL:', what) |
|
75 |
subprocess.call(['gnome-www-browser', what]) |
|
76 | ||
77 | ||
78 |
main() |
|
0 |
- |