예제 #1
0
    def test_verify_payment_function_on_fail(self, mock_post):
        mock_post.return_value = self.mock_request(
            {
                "status": False,
                "message": "Invalid key"
            }, status_code=400)
        instance = PaystackAPI()
        response = instance.verify_payment("12345", amount=27000)

        self.assertFalse(response[0])
        self.assertEqual(response[1], "Could not verify transaction")
예제 #2
0
 def setUp(self):
     self.api = PaystackAPI(public_key="public_key",
                            secret_key="secret_key",
                            django=False,
                            base_url=PAYSTACK_API_URL)
     self.headers = {
         'Authorization': "Bearer {}".format(self.api.secret_key),
         'Content-Type': 'application/json'
     }
예제 #3
0
    def __init__(self, environment='dev'):
        self.api = PaystackAPI(django=False,
                               base_url=PAYSTACK_BASE_URL,
                               public_key=keys[environment]['public_key'],
                               secret_key=keys[environment]['secret_key'])

        self.headers = {
            "Authorization": "Bearer %s" % keys[environment]['secret_key'],
            "Content-Type": "application/json",
        }
예제 #4
0
 def test_verify_payment_function_on_success(self, mock_post):
     mock_post.return_value = self.mock_request({
         "status": True,
         "message": "Verification successful",
         "data": {
             "amount": 27000,
             "currency": "NGN",
             "transaction_date": "2016-10-01T11:03:09.000Z",
             "status": "success",
             "reference": "DG4uishudoq90LD",
             "domain": "test",
             "metadata": 0,
             "gateway_response": "Successful",
             "message": None,
             "channel": "card",
             "ip_address": "41.1.25.1",
             "log": {
                 "time_spent":
                 9,
                 "attempts":
                 1,
                 "authentication":
                 None,
                 "errors":
                 0,
                 "success":
                 True,
                 "mobile":
                 False,
                 "input": [],
                 "channel":
                 None,
                 "history": [{
                     "type": "input",
                     "message":
                     "Filled these fields: card number, card expiry, card cvv",
                     "time": 7
                 }, {
                     "type": "action",
                     "message": "Attempted to pay",
                     "time": 7
                 }, {
                     "type": "success",
                     "message": "Successfully paid",
                     "time": 8
                 }, {
                     "type": "close",
                     "message": "Page closed",
                     "time": 9
                 }]
             },
             "fees": None,
             "authorization": {
                 "authorization_code": "AUTH_8dfhjjdt",
                 "card_type": "visa",
                 "last4": "1381",
                 "exp_month": "08",
                 "exp_year": "2018",
                 "bin": "412345",
                 "bank": "TEST BANK",
                 "channel": "card",
                 "signature": "SIG_idyuhgd87dUYSHO92D",
                 "reusable": True,
                 "country_code": "NG"
             },
             "customer": {
                 "id": 84312,
                 "customer_code": "CUS_hdhye17yj8qd2tx",
                 "first_name": "BoJack",
                 "last_name": "Horseman",
                 "email": "*****@*****.**"
             },
             "plan": "PLN_0as2m9n02cl0kp6"
         }
     })
     instance = PaystackAPI()
     response = instance.verify_payment("12345", amount=27000)
     mock_post.assert_called_once_with(
         "{}/transaction/verify/12345".format(instance.base_url),
         headers={'Authorization': "Bearer {}".format(instance.secret_key)})
     self.assertTrue(response[0])
     self.assertEqual(response[1], "Verification successful")
예제 #5
0
def paystack_api():
    return PaystackAPI(public_key="public_key",
                       secret_key="secret_key",
                       django=False,
                       base_url=PAYSTACK_API_URL)