-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspec.py
61 lines (50 loc) · 2.23 KB
/
spec.py
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
import processout
from processout.errors.notfounderror import NotFoundError
from processout.gatewayrequest import GatewayRequest
def main():
client = processout.ProcessOut("test-proj_gAO1Uu0ysZJvDuUpOGPkUBeE3pGalk3x",
"key_sandbox_mah31RDFqcDxmaS7MvhDbJfDJvjtsFTB")
# Create and fetch an invoice
invoice = client.new_invoice({
"name": "Test invoice",
"amount": "9.99",
"currency": "USD"
}).create()
assert invoice.id != "", "The invoice ID should not be empty"
fetched = client.new_invoice().find(invoice.id)
assert fetched.id != "", "The fetched invoice ID should not be empty"
assert invoice.id == fetched.id, "The invoices ID should be equal"
# Capture an invoice
gr = GatewayRequest("gway_conf_44ae90db0a62f819a404ef6a8ff994ca", "POST", "https://processout.com?token=test-valid", {
"Content-Type": "application/json"
}, "")
transaction = invoice.capture(gr.to_string())
assert transaction.status == "completed", "The transaction status was not completed"
# Expand the gateway configuration used on the transaction
transaction = transaction.find(transaction.id, {
"expand": ["gateway_configuration"]
})
assert transaction.gateway_configuration.id != "", "The transaction gateway configuration ID is empty"
# Fetch the customers
client.new_customer().all()
# Create a subscription for a customer
customer = client.new_customer().create()
assert customer.id != "", "The created customer ID should not be empty"
subscription = client.new_subscription({
"customer_id": customer.id,
"name": "Test subscription",
"amount": "9.99",
"currency": "USD",
"interval": "1d"
}).create()
assert subscription.id != "", "The created subscription ID should not be empty"
# Expand a customers' project and fetch gateways
customer = client.new_customer().create({"expand": ["project"]})
assert customer.project != None, "The customer project should be expanded"
# Check error code
try:
pass
except NotFoundError as err:
assert err.code == "resource.customer.not-found", "The error code was invalid"
if __name__ == "__main__":
main()