Skip to content

add cancel uma invitation mutation to py sdk #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: 05-27-add_create_invitation_with_payments_to_lightspark_sdk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions lightspark/lightspark_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
from lightspark.requests.requester import Requester
from lightspark.scripts.bitcoin_fee_estimate import BITCOIN_FEE_ESTIMATE_QUERY
from lightspark.scripts.cancel_invoice import CANCEL_INVOICE_MUTATION
from lightspark.scripts.cancel_uma_invitation import CANCEL_UMA_INVITATION_MUTATION
from lightspark.scripts.claim_uma_invitation import (
CLAIM_UMA_INVITATION_MUTATION,
CLAIM_UMA_INVITATION_WITH_INCENTIVES_MUTATION,
Expand Down Expand Up @@ -1020,34 +1021,52 @@ def fail_htlcs(self, invoice_id: str, cancel_invoice: bool = True) -> str:
def create_uma_invitation_with_payment(
self,
inviter_uma: str,
payment_amount: float,
payment_currency: Any,
amount_to_send: dict,
expires_at: str,
) -> UmaInvitation:
"""
Creates a new UMA invitation with payment.

Args:
inviter_uma: The UMA of the inviter.
payment_amount: The amount to be paid.
payment_currency: The currency object (should have code, symbol, name, decimals attributes).
amount_to_send: A dict with 'amount' and 'currency' keys. 'currency' should be a dict with code, symbol, name, decimals.
expires_at: The expiration datetime as an ISO8601 string.
"""
payment_amount = amount_to_send["amount"]
payment_currency = amount_to_send["currency"]
json = self._requester.execute_graphql(
CREATE_UMA_INVITATION_WITH_PAYMENT_MUTATION,
{
"inviter_uma": inviter_uma,
"payment_amount": payment_amount,
"payment_currency_code": payment_currency.code,
"payment_currency_symbol": payment_currency.symbol,
"payment_currency_name": payment_currency.name,
"payment_currency_decimals": payment_currency.decimals,
"payment_currency_code": payment_currency["code"],
"payment_currency_symbol": payment_currency["symbol"],
"payment_currency_name": payment_currency["name"],
"payment_currency_decimals": payment_currency["decimals"],
"expires_at": expires_at,
},
)
return UmaInvitation_from_json(
self._requester, json["create_uma_invitation_with_payment"]["invitation"]
)

def cancel_uma_invitation(
self,
invitation_code: str,
) -> UmaInvitation:
"""
Cancels a UMA invitation.

Args:
invitation_code: The invitation code to cancel.
"""
json = self._requester.execute_graphql(
CANCEL_UMA_INVITATION_MUTATION,
{"invitation_code": invitation_code},
)
return UmaInvitation_from_json(
self._requester, json["cancel_uma_invitation"]["invitation"]
)


E614_REGEX = re.compile(r"^\+?[1-9]\d{1,14}$")
19 changes: 19 additions & 0 deletions lightspark/scripts/cancel_uma_invitation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved

from lightspark.objects.UmaInvitation import FRAGMENT as INVITATION_FRAGMENT

CANCEL_UMA_INVITATION_MUTATION = f"""
mutation CancelUmaInvitation(
$invite_code: String!
) {{
cancel_uma_invitation(input: {{
invite_code: $invite_code
}}) {{
invitation {{
...UmaInvitationFragment
}}
}}
}}

{INVITATION_FRAGMENT}
"""