Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env python3
from sys import argv
from requests import post
from json import dumps
def main():
clientAPIRoot, issuerAPIRoot = argv[1:]
voucher = "0123456789"
zkapauthz = clientAPIRoot + "/storage-plugins/privatestorage-zkapauthorizer-v1"
# Simulate a payment for a voucher.
post(
issuerAPIRoot + "/v1/stripe/webhook",
dumps(charge_succeeded_json(voucher)),
)
# Tell the client to redeem the voucher.
post(
zkapauthz + "/voucher",
dumps({"voucher": voucher}),
)
# Poll the vouchers list for a while to see it get redeemed.
expected = {"number": voucher, "redeemed": True}
retry(
"find redeemed voucher",
lambda: expected == get(zkapauthz + "/voucher/" + voucher),
)
def retry(description, f):
for i in range(60):
print("trying to {}...".format(description))
if f():
print("{} succeeded".format(description))
break
sleep(1.0)
raise ValueError("failed to {} after many tries".format(description))
def charge_succeeded_json(voucher):
# This structure copy/pasted from Stripe webhook web interface.
base_payload = {
"id": "evt_1FKSX2DeTd13VRuuhPaUDA2f",
"object": "event",
"api_version": "2016-07-06",
"created": 1568910660,
"data": {
"object": {
"id": "ch_1FKSX2DeTd13VRuuG9BXbqji",
"object": "charge",
"amount": 999,
"amount_refunded": 0,
"application": None,
"application_fee": None,
"application_fee_amount": None,
"balance_transaction": "txn_1FKSX2DeTd13VRuuqO1CJZ1e",
"billing_details": {
"address": {
"city": None,
"country": None,
"line1": None,
"line2": None,
"postal_code": None,
"state": None
},
"email": None,
"name": None,
"phone": None
},
"captured": True,
"created": 1568910660,
"currency": "usd",
"customer": None,
"description": None,
"destination": None,
"dispute": None,
"failure_code": None,
"failure_message": None,
"fraud_details": {
},
"invoice": None,
"livemode": False,
"metadata": {
"Voucher": None,
},
"on_behalf_of": None,
"order": None,
"outcome": {
"network_status": "approved_by_network",
"reason": None,
"risk_level": "normal",
"risk_score": 44,
"seller_message": "Payment complete.",
"type": "authorized"
},
"paid": True,
"payment_intent": None,
"payment_method": "card_1FKSX2DeTd13VRuus5VEjmjG",
"payment_method_details": {
"card": {
"brand": "visa",
"checks": {
"address_line1_check": None,
"address_postal_code_check": None,
"cvc_check": None
},
"country": "US",
"exp_month": 9,
"exp_year": 2020,
"fingerprint": "HTJeRR4MXhAAkctF",
"funding": "credit",
"last4": "4242",
"three_d_secure": None,
"wallet": None
},
"type": "card"
},
"receipt_email": None,
"receipt_number": None,
"receipt_url": "https://pay.stripe.com/receipts/acct_198xN4DeTd13VRuu/ch_1FKSX2DeTd13VRuuG9BXbqji/rcpt_Fq8oAItSiNmcm0beiie6lUYin920E7a",
"refunded": False,
"refunds": {
"object": "list",
"data": [
],
"has_more": False,
"total_count": 0,
"url": "/v1/charges/ch_1FKSX2DeTd13VRuuG9BXbqji/refunds"
},
"review": None,
"shipping": None,
"source": {
"id": "card_1FKSX2DeTd13VRuus5VEjmjG",
"object": "card",
"address_city": None,
"address_country": None,
"address_line1": None,
"address_line1_check": None,
"address_line2": None,
"address_state": None,
"address_zip": None,
"address_zip_check": None,
"brand": "Visa",
"country": "US",
"customer": None,
"cvc_check": None,
"dynamic_last4": None,
"exp_month": 9,
"exp_year": 2020,
"fingerprint": "HTJeRR4MXhAAkctF",
"funding": "credit",
"last4": "4242",
"metadata": {
},
"name": None,
"tokenization_method": None
},
"source_transfer": None,
"statement_descriptor": None,
"statement_descriptor_suffix": None,
"status": "succeeded",
"transfer_data": None,
"transfer_group": None
}
},
"livemode": False,
"pending_webhooks": 2,
"request": "req_5ozjOIAcOkvVUK",
"type": "charge.succeeded"
}
# Indicate the voucher the payment references.
base_payload["data"]["object"]["metadata"]["Voucher"] = voucher
return base_payload
if __name__ == '__main__':
main()