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

Commit 434fe1c

Browse files
nuhamozainiecleel
authored andcommitted
New update for create() forbidding (#6)
* new version to forbid create(), fixes and refactoring * -- * -- * v0.6.1 * v0.6.1 - create() for Invoice only + fixes * Create invoice test
1 parent 7261505 commit 434fe1c

13 files changed

Lines changed: 23 additions & 119 deletions

File tree

moyasar/actions/create.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55

66
class Create(Constructor):
7-
def __init__(self, data):
8-
super().__init__(**data)
9-
107

118
@classmethod
129
def create_url(cls):
@@ -16,4 +13,4 @@ def create_url(cls):
1613
def create(cls, data):
1714
response = moyasar.request('POST', cls.create_url(), data)
1815
response = json.loads(response.text)
19-
return cls(response)
16+
return cls(response)

moyasar/actions/fetch.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55

66
class Fetch(Constructor):
7-
def __init__(self, data):
8-
super().__init__(data)
97

108
@classmethod
119
def fetch_url(cls, id):

moyasar/actions/list.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55

66
class List(Constructor):
7-
def __init__(self, data):
8-
super().__init__(data)
97

108
@classmethod
119
def list_url(cls):

moyasar/constructor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Constructor:
22

3-
def __init__(self, **kwargs):
4-
for key in kwargs:
5-
setattr(self, key, kwargs[key])
3+
def __init__(self, data):
4+
for key in data:
5+
setattr(self, key, data[key])

moyasar/invoice.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from moyasar.actions.create import Create
12
from moyasar.resource import Resource
23
from moyasar.actions.cancel import Cancel
34

45

5-
class Invoice(Resource, Cancel):
6+
class Invoice(Resource, Cancel, Create):
67
pass

moyasar/payment.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55

66
class Source(Constructor):
7-
def __init__(self, **kwargs):
8-
super().__init__(**kwargs)
7+
def __init__(self, data):
8+
super().__init__(data)
99

1010
@classmethod
1111
def build(cls, source):
@@ -18,12 +18,12 @@ def build(cls, source):
1818
@classmethod
1919
def source_to_creditcard(cls, data):
2020
data.pop('type')
21-
return CreditCard(**data)
21+
return CreditCard(data)
2222

2323
@classmethod
2424
def source_to_sadad(cls, data):
2525
data.pop('type')
26-
return Sadad(**data)
26+
return Sadad(data)
2727

2828

2929
class CreditCard(Source):
@@ -42,4 +42,4 @@ def __init__(self, data):
4242
def refund(self, amount=None):
4343
super().refund(amount)
4444
self.source = Source.build(self.source)
45-
return self
45+
return self

moyasar/resource.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from moyasar.actions.fetch import Fetch
22
from moyasar.actions.list import List
3-
from moyasar.actions.create import Create
43
from moyasar.actions.update import Update
54

65

7-
class Resource(Fetch, List, Create, Update):
8-
pass
6+
class Resource(Fetch, List, Update):
7+
pass

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
long_description = fh.read()
55
setuptools.setup(
66
name="moyasar",
7-
version="0.6.0",
7+
version="0.6.1",
88
author="Moyasar",
99
author_email="developers@moyasar.com",
1010
description="Moyasar Python language wrapper",
@@ -22,5 +22,5 @@
2222
'httpretty',
2323
'pytest'
2424
],
25-
download_url='https://github.com/moyasar/moyasar-python/archive/v0.6.0.tar.gz'
25+
download_url='https://github.com/moyasar/moyasar-python/archive/v0.6.1.tar.gz'
2626
)

tests/moyasar/invoice_test.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import os
2-
import json
3-
import pytest
4-
import tests.server_stubs as ss
1+
import copy
2+
53
import moyasar
64
import tests.fixtures.fixtures as f
7-
import copy
5+
import tests.server_stubs as ss
86

97

108
def test_create_should_return_intiated_invoice_for_sadad_source():

tests/moyasar/payment_test.py

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,8 @@
1-
import moyasar
2-
import tests.server_stubs as ss
3-
import tests.fixtures.fixtures as f
41
import copy
5-
import pytest
6-
7-
8-
def test_create_should_return_intiated_payment_for_sadad_source():
9-
params = {"amount": 1000, "currency": "SAR", "description": "Test"}
10-
ss.stub_server_request("post", moyasar.Payment.create_url(),
11-
resource=f.payment, status=200)
12-
moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2'
13-
payment = moyasar.Payment.create(params)
14-
assert isinstance(payment, moyasar.Payment)
15-
assert payment.status == "initiated"
16-
assert int(payment.amount) == params['amount']
17-
assert payment.currency == params['currency']
18-
assert payment.description == params['description']
19-
20-
21-
def test_create_with_amount_less_than_100_cent_should_raise_validation_errror():
22-
modified_resource = copy.deepcopy(f.payment)
23-
modified_resource.update({"amount": 90})
24-
ss.stub_server_request('post', moyasar.Payment.create_url(), resource=modified_resource,
25-
status=400, error_message="Validation Failed",
26-
errors={"amount": "must be greater than 99"})
27-
assert pytest.raises(Exception)
28-
29-
30-
def test_create_payment_for_inovice_should_be_acceptable():
31-
ss.stub_server_request("get", moyasar.Invoice.list_url(),
32-
resource=f.invoices, status=200)
33-
invoices = moyasar.Invoice.list()
34-
first_invoice_id = ''
35-
for key, val in invoices[0].__dict__.items():
36-
if key == "id":
37-
first_invoice_id = val
382

39-
modified_resource = copy.deepcopy(f.payment)
40-
modified_resource.update({"invoice_id": first_invoice_id})
41-
ss.stub_server_request("post", moyasar.Payment.create_url(),
42-
resource=modified_resource, status=200)
43-
moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2'
44-
payment = moyasar.Payment.create(modified_resource)
45-
assert isinstance(payment, moyasar.Payment)
46-
assert payment.invoice_id == first_invoice_id
3+
import moyasar
4+
import tests.fixtures.fixtures as f
5+
import tests.server_stubs as ss
476

487

498
def test_list_should_return_list_of_payment_objects():
@@ -87,29 +46,6 @@ def test_update_should_update_payment_description():
8746
assert new_description["description"] == after_updated.description
8847

8948

90-
# def test_refund_should_operate_normally_by_recharging_back_all_amount_as_a_default():
91-
# id = '328f5dca-91ec-435d-b13f-86052a1d0f7b'
92-
# ss.stub_server_request("get", moyasar.Payment.fetch_url(id),
93-
# resource=f.payment, status=200)
94-
# moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2'
95-
# original = moyasar.Payment.fetch(id)
96-
# params = {'status': 'refunded', 'refunded': original.amount}
97-
# custom_invoice = copy.deepcopy(f.payment)
98-
# custom_invoice.update(params)
99-
# ss.stub_server_request("post", f'{moyasar.api_url}/payments/{id}/refund',
100-
# resource=custom_invoice, status=200)
101-
# moyasar.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2'
102-
# refunded = original.refund(amount=original.amount)
103-
104-
105-
def test_refund_should_accept_partial_refund_amounts():
106-
pass
107-
108-
109-
def test_refund_with_failed_payment_should_raise_invalid_request_error():
110-
pass
111-
112-
11349
def test_eqaulity_check_holds_among_identical_payments_only():
11450
id = '1b82356d-b5fd-46f8-bde9-3680d62f289a'
11551
ss.stub_server_request("get", moyasar.Payment.fetch_url(id),

0 commit comments

Comments
 (0)