def execute_transaction(self, transaction, request):
        """
        :param transaction: A Instamojo transaction in Initial or Pending state.
        :param transaction: The HTTP Request
        :return: True on success, False on failure.
        """

        # customer_details = transaction.payment_method.archived_customer

        customer = transaction.payment_method.customer

        instamojo_request = dict(
            redirect_url=request.build_absolute_uri(
                get_payment_complete_url(transaction, request)),
            buyer_name=customer.first_name,
            webhook=request.build_absolute_uri(
                reverse('instamojo-webhook',
                        kwargs=dict(token=_get_jwt_token(transaction)))))

        try:
            instamojo_response = self.instamojo_wrapper.payment_request_create(
                'SpotDraft Subscription Charges', str(transaction.amount),
                **instamojo_request)
        except Exception as error:
            logger.error("Instamojo create request failed %r", error)
            transaction.fail(fail_reason=str(error))
            transaction.save()
            return False

        return self._parse_result(transaction, instamojo_response)
示例#2
0
    def test_get_transaction_from_token(self):
        transaction = TransactionFactory()

        mocked_view = MagicMock()
        token = _get_jwt_token(transaction)

        self.assertEquals(get_transaction_from_token(mocked_view)(None, token),
                          mocked_view())
        mocked_view.has_calls([call(None, transaction, False), call()])
示例#3
0
    def test_get_transaction_from_token(self):
        transaction = TransactionFactory()

        mocked_view = MagicMock()
        token = _get_jwt_token(transaction)

        self.assertEqual(get_transaction_from_token(mocked_view)(None, token),
                         mocked_view())
        mocked_view.has_calls([call(None, transaction, False), call()])
示例#4
0
    def test_get_transaction_from_expired_token(self):
        transaction = TransactionFactory()

        mocked_view = MagicMock()
        with patch('silver.utils.payments.datetime') as mocked_datetime:
            mocked_datetime.utcnow.return_value = datetime.utcnow() - timedelta(days=2 * 365)
            token = _get_jwt_token(transaction)

        self.assertEquals(get_transaction_from_token(mocked_view)(None, token),
                          mocked_view())
        mocked_view.has_calls([call(None, transaction, True), call()])
示例#5
0
    def test_get_transaction_from_expired_token(self):
        transaction = TransactionFactory()

        mocked_view = MagicMock()
        with patch('silver.utils.payments.datetime') as mocked_datetime:
            mocked_datetime.utcnow.return_value = datetime.utcnow() - timedelta(days=2 * 365)
            token = _get_jwt_token(transaction)

        self.assertEqual(get_transaction_from_token(mocked_view)(None, token),
                         mocked_view())
        mocked_view.has_calls([call(None, transaction, True), call()])
示例#6
0
    def test_get_jwt_token(self):
        uuid = UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e', version=4)
        transaction = TransactionFactory(uuid=uuid)

        expected_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0cmFuc2FjdG' \
                         'lvbiI6IjZmYTQ1OWVhLWVlOGEtNGNhNC04OTRlLWRiNzdlMTYwM' \
                         'zU1ZSIsImV4cCI6MTQ5Nzk2NTY0MH0.-bpx5A3DfSe3-HO6aH_g' \
                         'lS8adcCxUn8lSK1-RPxohhI'
        with patch('silver.utils.payments.datetime') as mocked_datetime:
            mocked_datetime.utcnow.return_value = datetime.strptime(
                'Jun 20 2017 1:33PM', '%b %d %Y %I:%M%p')
            self.assertEqual(_get_jwt_token(transaction), expected_token)
示例#7
0
def spec_transaction_pay_url(transaction):
    return absolute_url(reverse("payment", args=[_get_jwt_token(transaction)]))