forked from glim/rest-api-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
record_payment.py
85 lines (78 loc) · 2.22 KB
/
record_payment.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Example demonstrating creating an invoice, sending it
# (which changes its status from draft to sent)
# and recording a payment on the send invoice
import paypalrestsdk
from paypalrestsdk import Invoice
import logging
logging.basicConfig(level=logging.DEBUG)
paypalrestsdk.configure({
"mode": "<MODE>", # sandbox or live
"client_id": "<CLIENT_ID>",
"client_secret": "<CLIENT_SECRET>"})
invoice = Invoice({
"merchant_info": {
"email": "[email protected]",
"first_name": "Dennis",
"last_name": "Doctor",
"business_name": "Medical Professionals, LLC",
"phone": {
"country_code": "001",
"national_number": "5032141716"
},
"address": {
"line1": "1234 Main St.",
"city": "Portland",
"state": "OR",
"postal_code": "97217",
"country_code": "US"
}
},
"billing_info": [{"email": "[email protected]"}],
"items": [
{
"name": "Sutures",
"quantity": 100,
"unit_price": {
"currency": "USD",
"value": 5
}
}
],
"note": "Medical Invoice 16 Jul, 2013 PST",
"payment_term": {
"term_type": "NET_45"
},
"shipping_info": {
"first_name": "Sally",
"last_name": "Patient",
"business_name": "Not applicable",
"phone": {
"country_code": "001",
"national_number": "5039871234"
},
"address": {
"line1": "1234 Broad St.",
"city": "Portland",
"state": "OR",
"postal_code": "97216",
"country_code": "US"
}
}
})
if invoice.create():
print("Invoice[%s] created successfully" % (invoice.id))
else:
print(invoice.error)
if invoice.send(): # return True or False
print("Invoice[%s] send successfully" % (invoice.id))
else:
print(invoice.error)
payment_attr = {
"method": "CASH",
"date": "2014-07-10 03:30:00 PST",
"note": "Cash received."
}
if invoice.record_payment(payment_attr): # return True or False
print("Payment record on Invoice[%s] successfully" % (invoice.id))
else:
print(invoice.error)