mirror of
https://github.com/yawaflua/Py-SPW.git
synced 2025-12-10 12:29:30 +02:00
Upload 1.5.0 version
Upload docs
This commit is contained in:
14
examples/check_access.py
Normal file
14
examples/check_access.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import pyspw
|
||||
|
||||
|
||||
# Init library
|
||||
api = pyspw.SpApi(card_id='card_id',
|
||||
card_token='card_token')
|
||||
|
||||
# Check access to server
|
||||
print(api.check_access('287598524017803264')) # True
|
||||
print(api.check_access('289341856083607552')) # False
|
||||
|
||||
|
||||
# Check more than one access
|
||||
print(api.check_accesses(['403987036219899908', '558667431187447809'], delay=1)) # False, True
|
||||
9
examples/check_api_work.py
Normal file
9
examples/check_api_work.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import pyspw
|
||||
|
||||
# Init library
|
||||
api = pyspw.SpApi(card_id='card_id',
|
||||
card_token='card_token')
|
||||
|
||||
|
||||
# Checking
|
||||
print(api.ping())
|
||||
48
examples/create_payment_link.py
Normal file
48
examples/create_payment_link.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import json
|
||||
|
||||
import pyspw
|
||||
from pyspw.Parameters import Payment
|
||||
|
||||
|
||||
# Init library
|
||||
api = pyspw.SpApi(card_id='card_id',
|
||||
card_token='card_token')
|
||||
|
||||
|
||||
# Constructing payment
|
||||
payment = Payment(
|
||||
amount=150, # Payment amount (You can't set more than one shulker diamond ore)
|
||||
redirectUrl='https://spwdev.xyz/', # URL which redirects user after successful payment
|
||||
webhookUrl='https://spwdev.xyz/api/webhook_spw', # URL which receive webhook of successful payment with data
|
||||
data=json.dumps({ # Useful data which received with webhook on webhookUrl
|
||||
"type": "prepayment",
|
||||
"order": 987951455
|
||||
})
|
||||
)
|
||||
|
||||
# Create payment link
|
||||
print(api.create_payment(payment))
|
||||
|
||||
|
||||
# Create more than one payment link
|
||||
prepayment = Payment(
|
||||
amount=150,
|
||||
redirectUrl='https://spwdev.xyz/',
|
||||
webhookUrl='https://spwdev.xyz/api/webhook_spw',
|
||||
data=json.dumps({
|
||||
"type": "prepayment",
|
||||
"order": 987951455
|
||||
})
|
||||
)
|
||||
|
||||
# clone similar payment
|
||||
post_payment = prepayment
|
||||
post_payment.data = json.dumps({ # You can access to payment variables
|
||||
"type": "post-payment",
|
||||
"order": 987951455
|
||||
})
|
||||
|
||||
|
||||
# Create payment links
|
||||
api.create_payments([prepayment, post_payment], delay=0.6)
|
||||
# !Payments links valid for 5 minutes!
|
||||
8
examples/get_balance.py
Normal file
8
examples/get_balance.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import pyspw
|
||||
|
||||
# Init library
|
||||
api = pyspw.SpApi(card_id='card_id',
|
||||
card_token='card_token')
|
||||
|
||||
# Get card balance
|
||||
print(api.get_balance())
|
||||
37
examples/send_transaction.py
Normal file
37
examples/send_transaction.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import pyspw
|
||||
from pyspw.Parameters import Transaction
|
||||
|
||||
|
||||
# Init library
|
||||
api = pyspw.SpApi(card_id='card_id',
|
||||
card_token='card_token')
|
||||
|
||||
|
||||
# Constructing transaction
|
||||
transaction = Transaction(
|
||||
receiver='00001', # Card number of receiver
|
||||
amount=24, # Amount of diamond ore which you want to send
|
||||
comment='Buy diamond pickaxe' # Comment on transaction
|
||||
)
|
||||
|
||||
# Send transaction
|
||||
api.send_transaction(transaction)
|
||||
|
||||
|
||||
# Send more than one transaction
|
||||
salary = Transaction(
|
||||
receiver='00002',
|
||||
amount=100,
|
||||
comment='Salary for the January'
|
||||
)
|
||||
|
||||
|
||||
# You can get information from Transaction class
|
||||
tax = Transaction(
|
||||
receiver='00001',
|
||||
amount=round(salary.amount * 0.2), # take 20% from salary amount
|
||||
comment=f'Tax from `{salary.comment}`'
|
||||
)
|
||||
|
||||
# Send transactions
|
||||
api.send_transactions([tax, salary], delay=0.8)
|
||||
31
examples/users_actions.py
Normal file
31
examples/users_actions.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from typing import List
|
||||
|
||||
import pyspw
|
||||
from pyspw.User import User, Skin
|
||||
|
||||
# Init library
|
||||
api = pyspw.SpApi(card_id='card_id',
|
||||
card_token='card_token')
|
||||
|
||||
|
||||
# get user by discord id
|
||||
user: User = api.get_user('262632724928397312')
|
||||
|
||||
print(user.uuid) # user uuid
|
||||
print(user.nickname) # user nickname
|
||||
|
||||
# working with user skin
|
||||
skin: Skin = user.get_skin()
|
||||
|
||||
print(skin.variant) # skin variant (slim or classic)
|
||||
print(skin.get_head().get_url()) # get url of head
|
||||
bust_image: bytes = skin.get_bust().get_image() # get image (bytes) of skin bust
|
||||
|
||||
|
||||
# Get more than one user
|
||||
users: List[User] = api.get_users(['471286011851177994',
|
||||
'533953916082323456'], delay=0.4)
|
||||
|
||||
# print their uuids
|
||||
for player in users:
|
||||
print(player.uuid)
|
||||
19
examples/validate_webhook.py
Normal file
19
examples/validate_webhook.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import json
|
||||
|
||||
import pyspw
|
||||
|
||||
# Init library
|
||||
api = pyspw.SpApi(card_id='card_id',
|
||||
card_token='card_token')
|
||||
|
||||
|
||||
# Data received from webhook
|
||||
webhook_body = {
|
||||
"payer": "Nakke_",
|
||||
"amount": 10,
|
||||
"data": "brax10"
|
||||
}
|
||||
X_Body_Hash = "fba3046f2800197d8829556bdf2d04bf61a307d4ede31eb37fb4078d21e24d3e"
|
||||
|
||||
# Verify
|
||||
print(api.check_webhook(json.dumps(webhook_body), X_Body_Hash)) # True or False
|
||||
Reference in New Issue
Block a user