Пример #1
0
    def get_link_url(self, return_url=""):
        if self.link_url == "":
            # request only if not already requested
            client = QPClient(f":{settings.QUICKPAY_API_KEY}")

            parent = self.payment.family.get_first_parent()

            address = {
                "name": parent.name,
                "street": parent.address(),
                "city": parent.city,
                "zip_code": parent.zipcode,
                "att": self.payment.family.email,
                "country_code": "DNK",
            }

            variables = address.copy()
            variables["family"] = self.payment.family.email
            if self.payment.person:
                variables["person_name"] = self.payment.person.name
            if self.payment.activity:
                variables[
                    "activity_department"] = self.payment.activity.department.name
                variables["activity_name"] = self.payment.activity.name

            try:
                if self.transaction_id is None:
                    activity = client.post(
                        "/payments",
                        currency="DKK",
                        order_id=self.order_id,
                        variables=variables,
                        invoice_address=address,
                        shipping_address=address,
                    )
                    self.transaction_id = activity["id"]
                    self.save()

                if self.transaction_id is None:
                    raise Exception("we did not get a transaction_id")

                # Enable auto-capture if the activity starts this year
                link = client.put(
                    f"/payments/{self.transaction_id}/link",
                    amount=self.payment.amount_ore,
                    id=self.transaction_id,
                    continueurl=return_url,
                    cancelurl=return_url,
                    customer_email=self.payment.family.email,
                    autocapture=self.payment.activity.start_date.year <=
                    timezone.now().year,
                )

                self.link_url = link["url"]
                self.save()
            except Exception:
                # Something went wrong talking to quickpay - ask people to come back later
                return reverse("payment_gateway_error_view")

        return self.link_url
    def get_link_url(self, return_url=""):
        if self.link_url == "":
            # request only if not already requested
            client = QPClient(":{0}".format(settings.QUICKPAY_API_KEY))

            parent = self.payment.family.get_first_parent()

            address = {
                "name": parent.name,
                "street": parent.address(),
                "city": parent.city,
                "zip_code": parent.zipcode,
                "att": self.payment.family.email,
                "country_code": "DNK",
            }

            variables = address.copy()
            variables["family"] = self.payment.family.email
            if self.payment.person:
                variables["person_name"] = self.payment.person.name
            if self.payment.activity:
                variables["activity_department"] = self.payment.activity.department.name
                variables["activity_name"] = self.payment.activity.name

            try:
                if self.transaction_id is None:
                    activity = client.post(
                        "/payments",
                        currency="DKK",
                        order_id=self.order_id,
                        variables=variables,
                        invoice_address=address,
                        shipping_address=address,
                    )
                    self.transaction_id = activity["id"]
                    self.save()

                if self.transaction_id is None:
                    raise Exception("we did not get a transaction_id")

                link = client.put(
                    "/payments/{0}/link".format(self.transaction_id),
                    amount=self.payment.amount_ore,
                    id=self.transaction_id,
                    continueurl=return_url,
                    cancelurl=return_url,
                    customer_email=self.payment.family.email,
                    autocapture=True,
                )

                self.link_url = link["url"]
                self.save()
            except Exception:
                # Something went wrong talking to quickpay - ask people to come back later
                return reverse("payment_gateway_error_view")

        return self.link_url
    def get_link_url(self, return_url=''):
        if (self.link_url == ''):
            #request only if not already requested
            client = QPClient(":{0}".format(settings.QUICKPAY_API_KEY))

            parent = self.payment.family.get_first_parent()

            address = {
                'name': parent.name,
                'street': parent.address(),
                'city': parent.city,
                'zip_code': parent.zipcode,
                'att': self.payment.family.email,
                'country_code': 'DNK'
            }

            variables = address.copy()
            variables['family'] = self.payment.family.email
            if (self.payment.person):
                variables['person_name'] = self.payment.person.name
            if (self.payment.activity):
                variables[
                    'activity_department'] = self.payment.activity.department.name
                variables['activity_name'] = self.payment.activity.name

            try:
                if (self.transaction_id is None):
                    activity = client.post('/payments',
                                           currency='DKK',
                                           order_id=self.order_id,
                                           variables=variables,
                                           invoice_address=address,
                                           shipping_address=address)
                    self.transaction_id = activity['id']
                    self.save()

                if (self.transaction_id is None):
                    raise Exception('we did not get a transaction_id')

                link = client.put('/payments/{0}/link'.format(
                    self.transaction_id),
                                  amount=self.payment.amount_ore,
                                  id=self.transaction_id,
                                  continueurl=return_url,
                                  cancelurl=return_url,
                                  customer_email=self.payment.family.email,
                                  autocapture=True)

                self.link_url = link['url']
                self.save()
            except:
                # Something went wrong talking to quickpay - ask people to come back later
                return reverse('payment_gateway_error_view',
                               kwargs={'unique': self.payment.family.unique})

        return self.link_url
Пример #4
0
    def capture(self):
        client = QPClient(f":{settings.QUICKPAY_API_KEY}")

        status, body, headers = client.post(
            f"/payments/{self.transaction_id}/capture",
            amount=self.payment.amount_ore,
            raw=True,
        )

        if status == 202:
            self.payment.confirmed_dtm = timezone.now()
            self.payment.save()
Пример #5
0
    def update_status(self):
        client = QPClient(f":{settings.QUICKPAY_API_KEY}")

        # get payment id from order id
        transaction = client.get(f"/payments/{self.transaction_id}")

        if transaction["state"] == "processed" and transaction["accepted"]:
            self.payment.set_confirmed()
        if transaction["state"] == "new" and transaction["accepted"]:
            self.payment.set_accepted()
        if transaction["state"] == "rejected" and not transaction["accepted"]:
            self.payment.set_rejected(repr(transaction))
Пример #6
0
    def update_status(self):
        client = QPClient(":{0}".format(settings.QUICKPAY_API_KEY))

        # get payment id from order id
        transactions = client.get('/payments', order_id=self.order_id)

        if(len(transactions) > 0):
            transaction = transactions[0]

            if transaction['state'] == 'processed' and transaction['accepted']:
                self.payment.set_confirmed()
            if transaction['state'] == 'rejected' and not transaction['accepted']:
                self.payment.set_rejected(repr(transaction))
Пример #7
0
    def update_status(self):
        client = QPClient(":{0}".format(settings.QUICKPAY_API_KEY))

        # get payment id from order id
        transactions = client.get('/payments', order_id=self.order_id)

        if(len(transactions) > 0):
            transaction = transactions[0]

            if transaction['state'] == 'processed' and transaction['accepted']:
                self.payment.set_confirmed()
            if transaction['state'] == 'rejected' and not transaction['accepted']:
                self.payment.set_rejected(repr(transaction))
    def update_status(self):
        client = QPClient(":{0}".format(settings.QUICKPAY_API_KEY))

        # get payment id from order id
        transactions = client.get("/payments", order_id=self.order_id)

        if len(transactions) > 0:
            transaction = transactions[0]

            if transaction["state"] == "processed" and transaction["accepted"]:
                self.payment.set_confirmed()
            if transaction["state"] == "rejected" and not transaction["accepted"]:
                self.payment.set_rejected(repr(transaction))
    def update_status(self):
        client = QPClient(":{0}".format(settings.QUICKPAY_API_KEY))

        # get payment id from order id
        transactions = client.get("/payments", order_id=self.order_id)

        if len(transactions) > 0:
            transaction = transactions[0]

            if transaction["state"] == "processed" and transaction["accepted"]:
                self.payment.set_confirmed()
            if transaction[
                    "state"] == "rejected" and not transaction["accepted"]:
                self.payment.set_rejected(repr(transaction))
Пример #10
0
    def get_link_url(self, return_url=''):
        if(self.link_url == ''):
            #request only if not already requested
            client = QPClient(":{0}".format(settings.QUICKPAY_API_KEY))

            parent = self.payment.family.get_first_parent()

            address = {'name' : parent.name,
                       'street' : parent.address(),
                       'city' : parent.city,
                       'zip_code' : parent.zipcode,
                       'att' : self.payment.family.email,
                       'country_code' : 'DNK'
                       }

            variables = address.copy()
            variables['family'] = self.payment.family.email
            if(self.payment.person):
                variables['person_name'] = self.payment.person.name
            if(self.payment.activity):
                variables['activity_department'] = self.payment.activity.department.name
                variables['activity_name'] = self.payment.activity.name

            try:
                if(self.transaction_id == None):
                    activity = client.post('/payments', currency='DKK', order_id=self.order_id, variables=variables, invoice_address=address, shipping_address=address)
                    self.transaction_id = activity['id']
                    self.save()

                if(self.transaction_id == None):
                    raise Exception('we did not get a transaction_id')

                link = client.put(
                    '/payments/{0}/link'.format(self.transaction_id),
                    amount=self.payment.amount_ore,
                    id=self.transaction_id,
                    continueurl=return_url,
                    cancelurl=return_url,
                    customer_email=self.payment.family.email,
                    autocapture=True
                    )

                self.link_url = link['url']
                self.save()
            except:
                # Something went wrong talking to quickpay - ask people to come back later
                return reverse('payment_gateway_error_view', kwargs={'unique':self.payment.family.unique})

        return self.link_url
Пример #11
0
 def __init__(self):
     """Initialise the QuickPay client."""
     self.client = QPClient(f":{settings.QUICKPAY_API_KEY}")
Пример #12
0
 def setup(self):
     self.client = QPClient('foobar')
     self.api = self.client.api
     self.api.perform = MagicMock()
Пример #13
0
class TestQPClient(object):
    def setup(self):
        self.client = QPClient('foobar')
        self.api = self.client.api
        self.api.perform = MagicMock()

    def test_api_instance(self):
        assert isinstance(self.client.api, QPApi)

    def test_get_delegation(self):
        self.client.get("/dummy")
        self.api.perform.assert_called_once_with("get", "/dummy")

    def test_post_delegation(self):
        self.client.post("/dummy")
        self.api.perform.assert_called_once_with("post", "/dummy")

    def test_delete_delegation(self):
        self.client.delete("/dummy")
        self.api.perform.assert_called_once_with("delete", "/dummy")

    def test_put_delegation(self):
        self.client.put("/dummy")
        self.api.perform.assert_called_once_with("put", "/dummy")

    def test_patch_delegation(self):
        self.client.patch("/dummy")
        self.api.perform.assert_called_once_with("patch", "/dummy")

    def test_non_http_method(self):
        def request_foobar(client, path):
            return self.client.foobar(path)

        assert_raises(AttributeError, request_foobar, self.client, "/dummy")
Пример #14
0
def quickpay_client(currency: Optional[str] = None) -> QPClient:
    """Get QuickPay client proxy object"""
    secret = ":{0}".format(get_api_key(currency))
    return QPClient(secret)