Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ghimiresdp/nepali-wallets-python in…
Browse files Browse the repository at this point in the history
…to feature/khalti
  • Loading branch information
ghimiresdp committed Mar 6, 2023
2 parents 077112b + bdc1de8 commit ac5a289
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 21 deletions.
36 changes: 35 additions & 1 deletion CONTRIBUTION.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
# Instructions for contributors
# Instruction for contributors

> **Note**: _The project strictly uses `poetry` package manager so do not push
> any `requirements.txt` file or other package management files._
Rules to contribute to projects:

- The main goal of this project is to unify payment process so we must inherit
abstract classes for creating a new payment method.

- Do not use highly offensive or racist words anywhere including variable names,
examples, and requirement specification.

- The solution should be capable of running on all operating systems.
If not, mention in the respective section in documentation


## Placeholders
Placeholders are not strict and we may use any name for them, but please try to
name them so that everyone who understands English can understand them properly.

We may use name of fictional characters of Sci-fi movies too
but we should make sure that those names should not impact sentiments of people
of any region, race, or gender.

Examples of some placeholders:

1. **Person**: `John Doe` `Darth Vader`, `Sheldon`, `Iron Man`, `Yoda`, etc.
2. **Place**: `High Street`, `Wakanda`, `Vulkan`, `Tatooine`, etc.
3. **Organization**: `Ace`, `Galactic Republic`, `Jedi`, `Enterprise`, ``, etc.
4. **Domain Names** `example.com`, `starwars.com`, `johndoe.com`, etc.


> **Note**: All of the above guidelines are created just for the reference and
> may not be used as a proof for any legal actions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

An SDK for payment gateways integration in Nepal.

![GitHub last commit](https://img.shields.io/github/last-commit/code-wonk/nepali-wallets-python)  
![GitHub issues](https://img.shields.io/github/issues/code-wonk/nepali-wallets-python)  


> **Note**: <i> If you are a contributor or want to contribute to this project,
> you can check the [contribution](CONTRIBUTION.md) section to get started.</i>
Expand Down
14 changes: 12 additions & 2 deletions nepali_wallets/client/_khalti.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,18 @@ def complete_payment(self, token: str, confirmation_code: str):
print("payment completion is automatically handled by the khalti client itself")
raise NotImplementedError()

def verify_payment(self, token: str):
raise NotImplementedError()
def verify_payment(self, intent: Union[KhaltiIntent, str]):
if isinstance(intent, KhaltiIntent):
intent = intent.id
return self.session.post(
f'{self.base_url}/epayment/lookup/',
data=json.dumps(
{
'pidx': intent
}
),
headers=self._get_request_headers()
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
40 changes: 26 additions & 14 deletions tests/clients/test_khalti.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,30 @@ def test_khali_intent__success(self):
}
)
assert intent.id is not None
assert 'pidx' in intent.data

def test_khalti_intent__status(self, khalti__intent):
print(khalti__intent.id)
data = khalti_client.verify_payment(khalti__intent)
print(data.text)

def test_khalti__payment(self, khalti__intent):
"""
To run this test case, you must provide -s argument since this test case needs user interaction
example 1: pytest -s
example 2: pytest -s -k khalti__payment
Once this test starts, the payment intent is created, at the time, you need to click the link generated
by khalti and complete payment with credentials as follows:
phone: 9800000000 / 9800000001 ... 9800000005
mpin: 1111
OTP: 987654
"""
print(khalti__intent.data)
print("Click the link, pay and continue")
intent = input(f'intent id [{khalti__intent.id}]: ')
data = khalti_client.verify_payment(intent or khalti__intent)
assert data.json()['status'] == 'Completed'

def test_khalti_intent__duplicate_order(self):
current_timestamp = datetime.now().timestamp()
data = {
'amount': 1000,
'order_id': f'test_order_{current_timestamp}',
'order_name': f"Test Order {current_timestamp}",
'customer_info': {
'name': 'John Doe',
'email': '[email protected]',
}
}
khalti_client.create_intent(**data)
intent = khalti_client.create_intent(**data)
assert intent.id is None
9 changes: 5 additions & 4 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
from datetime import datetime

__all__ = [
'intent__khalti',
'khalti__intent',
]


@pytest.fixture
def intent__khalti():
def khalti__intent():
current_timestamp = datetime.now().timestamp()
intent_response = khalti_client.create_intent(
intent = khalti_client.create_intent(
amount=1000,
order_id=f'order_{current_timestamp}',
order_name="Test Order",
Expand All @@ -19,4 +20,4 @@ def intent__khalti():
'email': '[email protected]',
}
)
return intent_response
return intent

0 comments on commit ac5a289

Please sign in to comment.