Skip to content

Commit ac5a289

Browse files
committed
Merge branch 'main' of github.com:ghimiresdp/nepali-wallets-python into feature/khalti
2 parents 077112b + bdc1de8 commit ac5a289

File tree

5 files changed

+82
-21
lines changed

5 files changed

+82
-21
lines changed

CONTRIBUTION.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
1-
# Instructions for contributors
1+
# Instruction for contributors
2+
3+
> **Note**: _The project strictly uses `poetry` package manager so do not push
4+
> any `requirements.txt` file or other package management files._
5+
6+
Rules to contribute to projects:
7+
8+
- The main goal of this project is to unify payment process so we must inherit
9+
abstract classes for creating a new payment method.
10+
11+
- Do not use highly offensive or racist words anywhere including variable names,
12+
examples, and requirement specification.
13+
14+
- The solution should be capable of running on all operating systems.
15+
If not, mention in the respective section in documentation
16+
17+
18+
## Placeholders
19+
Placeholders are not strict and we may use any name for them, but please try to
20+
name them so that everyone who understands English can understand them properly.
21+
22+
We may use name of fictional characters of Sci-fi movies too
23+
but we should make sure that those names should not impact sentiments of people
24+
of any region, race, or gender.
25+
26+
Examples of some placeholders:
27+
28+
1. **Person**: `John Doe` `Darth Vader`, `Sheldon`, `Iron Man`, `Yoda`, etc.
29+
2. **Place**: `High Street`, `Wakanda`, `Vulkan`, `Tatooine`, etc.
30+
3. **Organization**: `Ace`, `Galactic Republic`, `Jedi`, `Enterprise`, ``, etc.
31+
4. **Domain Names** `example.com`, `starwars.com`, `johndoe.com`, etc.
32+
33+
34+
> **Note**: All of the above guidelines are created just for the reference and
35+
> may not be used as a proof for any legal actions.

README.md

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

33
An SDK for payment gateways integration in Nepal.
44

5+
![GitHub last commit](https://img.shields.io/github/last-commit/code-wonk/nepali-wallets-python)  
6+
![GitHub issues](https://img.shields.io/github/issues/code-wonk/nepali-wallets-python)  
7+
8+
59
> **Note**: <i> If you are a contributor or want to contribute to this project,
610
> you can check the [contribution](CONTRIBUTION.md) section to get started.</i>
711

nepali_wallets/client/_khalti.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,18 @@ def complete_payment(self, token: str, confirmation_code: str):
7171
print("payment completion is automatically handled by the khalti client itself")
7272
raise NotImplementedError()
7373

74-
def verify_payment(self, token: str):
75-
raise NotImplementedError()
74+
def verify_payment(self, intent: Union[KhaltiIntent, str]):
75+
if isinstance(intent, KhaltiIntent):
76+
intent = intent.id
77+
return self.session.post(
78+
f'{self.base_url}/epayment/lookup/',
79+
data=json.dumps(
80+
{
81+
'pidx': intent
82+
}
83+
),
84+
headers=self._get_request_headers()
85+
)
7686

7787
def __init__(self, *args, **kwargs):
7888
super().__init__(*args, **kwargs)

tests/clients/test_khalti.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,30 @@ def test_khali_intent__success(self):
1616
}
1717
)
1818
assert intent.id is not None
19+
assert 'pidx' in intent.data
20+
21+
def test_khalti_intent__status(self, khalti__intent):
22+
print(khalti__intent.id)
23+
data = khalti_client.verify_payment(khalti__intent)
24+
print(data.text)
25+
26+
def test_khalti__payment(self, khalti__intent):
27+
"""
28+
To run this test case, you must provide -s argument since this test case needs user interaction
29+
30+
example 1: pytest -s
31+
example 2: pytest -s -k khalti__payment
32+
33+
Once this test starts, the payment intent is created, at the time, you need to click the link generated
34+
by khalti and complete payment with credentials as follows:
35+
36+
phone: 9800000000 / 9800000001 ... 9800000005
37+
mpin: 1111
38+
OTP: 987654
39+
"""
40+
print(khalti__intent.data)
41+
print("Click the link, pay and continue")
42+
intent = input(f'intent id [{khalti__intent.id}]: ')
43+
data = khalti_client.verify_payment(intent or khalti__intent)
44+
assert data.json()['status'] == 'Completed'
1945

20-
def test_khalti_intent__duplicate_order(self):
21-
current_timestamp = datetime.now().timestamp()
22-
data = {
23-
'amount': 1000,
24-
'order_id': f'test_order_{current_timestamp}',
25-
'order_name': f"Test Order {current_timestamp}",
26-
'customer_info': {
27-
'name': 'John Doe',
28-
'email': '[email protected]',
29-
}
30-
}
31-
khalti_client.create_intent(**data)
32-
intent = khalti_client.create_intent(**data)
33-
assert intent.id is None

tests/fixtures.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
from datetime import datetime
55

66
__all__ = [
7-
'intent__khalti',
7+
'khalti__intent',
88
]
99

10+
1011
@pytest.fixture
11-
def intent__khalti():
12+
def khalti__intent():
1213
current_timestamp = datetime.now().timestamp()
13-
intent_response = khalti_client.create_intent(
14+
intent = khalti_client.create_intent(
1415
amount=1000,
1516
order_id=f'order_{current_timestamp}',
1617
order_name="Test Order",
@@ -19,4 +20,4 @@ def intent__khalti():
1920
'email': '[email protected]',
2021
}
2122
)
22-
return intent_response
23+
return intent

0 commit comments

Comments
 (0)