Esempio n. 1
0
    def charge(self, email, auth_code, amount, reference=None,  metadata=None):
        """
        Charges a customer and returns the response
        
        args:
        auth_code -- Customer's auth code
        email -- Customer's email address
        amount -- Amount to charge
        reference -- optional
        metadata -- a list if json data objects/dicts
        """
        amount = utils.validate_amount(amount)

        if not email:
            raise InvalidDataError("Customer's Email is required to charge")

        if not auth_code:
            raise InvalidDataError("Customer's Auth code is required to charge") 
        
        url = self._url("/transaction/charge_authorization")
        payload = {
                    "authorization_code":auth_code, 
                    "email":email, 
                    "amount": amount,
                    "reference": reference,
                    "metadata": {"custom_fields":metadata}
                }

        return self._handle_request('POST', url, payload)
Esempio n. 2
0
    def initialize(self, email, amount, plan=None, reference=None, channel=None, metadata=None):
        """
        Initialize a transaction and returns the response
        
        args:
        email -- Customer's email address
        amount -- Amount to charge
        plan -- optional
        Reference -- optional
        channel -- channel type to use
        metadata -- a list if json data objects/dicts
        """
        amount = utils.validate_amount(amount)

        if not email:
            raise InvalidDataError("Customer's Email is required for initialization") 

        url = self._url("/transaction/initialize")
        payload = {
                    "email":email,
                    "amount": amount,
                    "reference": reference,
                    "plan": plan,
                    "channels": channel,
                    "metadata": {"custom_fields":metadata}
                }
        return self._handle_request('POST', url, payload)
Esempio n. 3
0
    def initialize(self, email, amount, plan=None, reference=None, channel=None, metadata=None):
        """
        Initialize a transaction and returns the response
        
        args:
        email -- Customer's email address
        amount -- Amount to charge
        plan -- optional
        Reference -- optional
        channel -- channel type to use
        metadata -- a list if json data objects/dicts
        """
        amount = utils.validate_amount(amount)

        if not email:
            raise InvalidDataError("Customer's Email is required for initialization") 

        url = self._url("/transaction/initialize")
        payload = {
                    "email":email,
                    "amount": amount,
                    "reference": reference,
                    "plan": plan,
                    "channels": channel,
                    "metadata": {"custom_fields":metadata}
                }
        return self._handle_request('POST', url, payload)
Esempio n. 4
0
    def charge(self, email, auth_code, amount, reference=None):
        """
        Charges a customer and returns the response
        
        args:
        auth_code -- Customer's auth code
        email -- Customer's email address
        amount -- Amount to charge
        reference -- optional
        """
        amount = utils.validate_amount(amount)

        if not email:
            raise InvalidDataError("Customer's Email is required to charge")

        if not auth_code:
            raise InvalidDataError("Customer's Auth code is required to charge") 
        
        url = self._url("/transaction/charge_authorization")
        payload = {
                    "authorization_code":auth_code, 
                    "email":email, 
                    "amount": amount,
                    "reference": reference
                }

        return self._handle_request('POST', url, payload)
Esempio n. 5
0
    def create(self, name, amount, interval, description=None, \
                send_invoices=False, send_sms=False, hosted_page=False, hosted_page_url=None, hosted_page_summary=None, currency=None):
        """
        Creates a new plan. Returns the plan details created

        args:
        name -- Name of the plan to create
        amount -- Amount to attach to this plan
        interval -- 'hourly', 'daily', 'weekly', 'monthly', 'annually'
        description -- Plan Description (optional)
        
        """
        interval = utils.validate_interval(interval)
        amount = utils.validate_amount(amount)

        url = self._url("/plan/")
        payload = {
                "name": name,
                "amount": amount,
                "interval": interval,
                "currency": currency,
                "send_sms": send_sms,
                "description": description,
                "hosted_page": hosted_page,
                "send_invoices": send_invoices,
                "hosted_page_url": hosted_page_url,
                "hosted_page_summary": hosted_page_summary,
                }
        return self._handle_request('POST', url, payload)
Esempio n. 6
0
 def update(self, plan_id, name, amount, interval, description=None, \
             send_invoices=False, send_sms=False, hosted_page=False, hosted_page_url=None, hosted_page_summary=None, currency=None):
     """
     Updates an existing plan given a plan id. Returns the plan details updated.
     
     args:
     plan_id -- Plan Id to update
     name -- New plan name
     amount -- New Amount to attach to this plan
     interval -- 'hourly', 'daily', 'weekly', 'monthly', 'annually'
     description -- Plan Description (optional)
     """
     interval = utils.validate_interval(interval)
     amount = utils.validate_amount(amount)
     
     url = self._url("/plan/{}/".format(plan_id))
     payload = {
             "name": name,
             "amount": amount,
             "interval": interval,
             "currency": currency,
             "send_sms": send_sms,
             "description": description,
             "hosted_page": hosted_page,
             "send_invoices": send_invoices,
             "hosted_page_url": hosted_page_url,
             "hosted_page_summary": hosted_page_summary,
             }
     return self._handle_request('PUT', url, payload)
Esempio n. 7
0
    def create(self, name, amount, interval, description=None, \
                send_invoices=False, send_sms=False, hosted_page=False, hosted_page_url=None, hosted_page_summary=None, currency=None):
        """
        Creates a new plan. Returns the plan details created

        args:
        name -- Name of the plan to create
        amount -- Amount to attach to this plan
        interval -- 'hourly', 'daily', 'weekly', 'monthly', 'annually'
        description -- Plan Description (optional)
        
        """
        interval = utils.validate_interval(interval)
        amount = utils.validate_amount(amount)

        url = self._url("/plan/")
        payload = {
            "name": name,
            "amount": amount,
            "interval": interval,
            "currency": currency,
            "send_sms": send_sms,
            "description": description,
            "hosted_page": hosted_page,
            "send_invoices": send_invoices,
            "hosted_page_url": hosted_page_url,
            "hosted_page_summary": hosted_page_summary,
        }
        return self._handle_request('POST', url, payload)
Esempio n. 8
0
    def update(self, plan_id, name, amount, interval, description=None, \
                send_invoices=False, send_sms=False, hosted_page=False, hosted_page_url=None, hosted_page_summary=None, currency=None):
        """
        Updates an existing plan given a plan id. Returns the plan details updated.
        
        args:
        plan_id -- Plan Id to update
        name -- New plan name
        amount -- New Amount to attach to this plan
        interval -- 'hourly', 'daily', 'weekly', 'monthly', 'annually'
        description -- Plan Description (optional)
        """
        interval = utils.validate_interval(interval)
        amount = utils.validate_amount(amount)

        url = self._url("/plan/{}/".format(plan_id))
        payload = {
            "name": name,
            "amount": amount,
            "interval": interval,
            "currency": currency,
            "send_sms": send_sms,
            "description": description,
            "hosted_page": hosted_page,
            "send_invoices": send_invoices,
            "hosted_page_url": hosted_page_url,
            "hosted_page_summary": hosted_page_summary,
        }
        return self._handle_request('PUT', url, payload)
Esempio n. 9
0
    def initialize(self, amount, recipient_code):
        """
        Initialize a transfer and returns the response
        
        amount -- Amount to charge
        recipient_code
        """
        amount = utils.validate_amount(amount)

        payload = {
            "amoun": amount,
            "recipient_code": recipient_code,
        }

        url = self._url("POST", "https://api.paystack.co/transfer", payload)
Esempio n. 10
0
    def transfer(self, recipient_code, amount, reason, reference=None):
        """
        Initiates transfer to a customer
        """
        amount = utils.validate_amount(amount)
        url = self._url("/transfer")
        payload = {
            "amount": amount,
            "reason": reason,
            "recipient": recipient_code,
            "source": "balance",
            "currency": "NGN",
        }
        if reference:
            payload.update({"reference": reference})

        return self._handle_request('POST', url, payload)