Skip to content
This repository was archived by the owner on Jun 26, 2025. It is now read-only.

Commit 5f867f8

Browse files
committed
initial changes for manual payment
1 parent 9c16a68 commit 5f867f8

4 files changed

Lines changed: 43 additions & 3 deletions

File tree

moyasar/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def fill_object(object, data):
1717
object.__setattr__(key, data[key])
1818

1919

20-
def request(http_verb, url, data, key=None):
20+
def request(http_verb, url, data=None, key=None):
2121
moyasar_key = key or api_key
2222

2323
if moyasar_key is None:

moyasar/actions/capture.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import moyasar
2+
import json
3+
4+
5+
class Capture:
6+
def capture_url(self, id):
7+
return f'{moyasar.resource_url(self.__class__.__name__)}/{id}/capture'.lower()
8+
9+
def capture(self, amount=None):
10+
data = None
11+
if amount is not None:
12+
data = {'amount': amount}
13+
14+
response = moyasar.request('POST', self.capture_url(self.id), data)
15+
response = json.loads(response.text)
16+
moyasar.fill_object(self, response)

moyasar/actions/void.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import moyasar
2+
import json
3+
4+
5+
class Void:
6+
def void_url(self, id):
7+
return f'{moyasar.resource_url(self.__class__.__name__)}/{id}/void'.lower()
8+
9+
def void(self):
10+
response = moyasar.request('POST', self.void_url(self.id))
11+
response = json.loads(response.text)
12+
moyasar.fill_object(self, response)

moyasar/payment.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from moyasar.resource import Resource
44
from moyasar.actions.refund import Refund
5+
from moyasar.actions.capture import Capture
6+
from moyasar.actions.void import Void
57
from moyasar.helpers import Constructor
68
from moyasar.helpers import Format
79

@@ -36,7 +38,7 @@ class Sadad(Source):
3638
pass
3739

3840

39-
class Payment(Resource, Refund, Format):
41+
class Payment(Resource, Refund, Capture, Void, Format):
4042

4143
def __init__(self, data):
4244
super().__init__(data)
@@ -45,4 +47,14 @@ def __init__(self, data):
4547
def refund(self, amount=None):
4648
super().refund(amount)
4749
self.source = Source.build(self.source)
48-
return self
50+
return self
51+
52+
def capture(self, amount=None):
53+
super().capture(amount)
54+
self.source = Source.build(self.source)
55+
return self
56+
57+
def void(self):
58+
super().void()
59+
self.source = Source.build(self.source)
60+
return self

0 commit comments

Comments
 (0)