-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34a0082
commit 2cf453d
Showing
1 changed file
with
116 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,16 +16,129 @@ pip install chargily-pay | |
```python | ||
from chargily_pay import ChargilyClient | ||
from chargily_pay.settings import CHARGILIY_TEST_URL | ||
from chargily_pay.entity import Checkout | ||
|
||
import requests | ||
|
||
# ============== | ||
# Init Chargily | ||
# ============== | ||
key = "YOUR_KEY" | ||
secret = "YOUR_SECRET" | ||
|
||
chargily = ChargilyClient(key, secret, CHARGILIY_TEST_URL) | ||
|
||
# ============== | ||
# Get Balance | ||
# ============== | ||
response = chargily.get_balance() | ||
|
||
# ============== | ||
# Create Customer | ||
# ============== | ||
from chargily_pay.entity import Customer, Address | ||
|
||
customer = Customer( | ||
name="Username", | ||
email="[email protected]", | ||
address=Address(address="Address", state="State", country="dz"), | ||
) | ||
response = chargily.create_customer(customer) | ||
|
||
# ============== | ||
# Create Product | ||
# ============== | ||
from chargily_pay.entity import Product | ||
|
||
product1 = Product( | ||
name="Product name", | ||
) | ||
chargily.create_product(product1) | ||
|
||
# ============== | ||
# Create Price | ||
# ============== | ||
from chargily_pay.entity import Product, Price | ||
|
||
product = Product( | ||
name="Product name", | ||
description="Product description", | ||
) | ||
response = chargily.create_product(product) | ||
product_id = response["id"] | ||
price = chargily.create_price(Price(amount=100, currency="dzd", product_id=product_id)) | ||
|
||
# ============== | ||
# Create Checkout | ||
# ============================= | ||
# Create Checkout With Product | ||
# ============================= | ||
|
||
from chargily_pay.entity import Product, Price | ||
from chargily_pay.entity import Checkout | ||
|
||
product = Product( | ||
name="Product name", | ||
description="Product description", | ||
) | ||
response = chargily.create_product(product) | ||
product_id = response["id"] | ||
price = chargily.create_price(Price(amount=100, currency="dzd", product_id=product_id)) | ||
price_id = price["id"] | ||
checkout = chargily.create_checkout( | ||
Checkout( | ||
items=[{"price": price_id, "quantity": 1}], | ||
success_url="https://example.com/success", | ||
failure_url="https://example.com/failure", | ||
) | ||
) | ||
|
||
# ============================= | ||
# Create Checkout With Product | ||
# ============================= | ||
from chargily_pay.entity import Checkout | ||
|
||
response = chargily.create_checkout( | ||
Checkout( | ||
amount=1000, | ||
currency="dzd", | ||
success_url="https://example.com/success", | ||
) | ||
) | ||
|
||
# ============================= | ||
# Expire Checkout | ||
# ============================= | ||
checkout_id = "checkout_id" | ||
chargily.expire_checkout(checkout_id) | ||
|
||
|
||
# ============== | ||
# Create Payment | ||
# ============== | ||
from chargily_pay.entity import Product, Price, PaymentItem, PaymentLink | ||
|
||
product = Product( | ||
name="Product name", | ||
description="Product description", | ||
) | ||
response = chargily.create_product(product) | ||
product_id = response["id"] | ||
|
||
price = Price(amount=100, currency="dzd", product_id=product_id) | ||
response = chargily.create_price(price) | ||
price_id = response["id"] | ||
|
||
payment_link = chargily.create_payment_link( | ||
PaymentLink( | ||
name="Payment link name", | ||
items=[ | ||
PaymentItem( | ||
price=price_id, | ||
quantity=1, | ||
) | ||
], | ||
) | ||
) | ||
|
||
|
||
print(chargily.get_balance()) | ||
``` | ||
|