Beispiel #1
0
    def recurring(self, credit_card_details, options=None):
        """
            Recurring Payment Implementation using eWay recurring API (http://www.eway.com.au/developers/api/recurring)

            Input Parameters:
                ( Please find the details here in this Gist: https://gist.github.com/df67e02f7ffb39f415e6 )
                credit_card   :    Customer Credit Card details
                options       :    Customer and Recurring Payment details

            Output Dict:
                status: 'SUCCESS' or 'FAILURE'
                response : Response list of rebill event request in order of provided input
                           in options["customer_rebill_details"] list.
        """
        error_response = {}
        try:
            if not options:
                error_response = {"reason": "Not enough information Available!"}
                raise

            '''
                # Validate Entered credit card details.
            '''
            credit_card = CreditCard(**credit_card_details)
            if not self.validate_card(credit_card):
                raise InvalidCard("Invalid Card")

            rebillClient = RebillEwayClient(
                customer_id=self.customer_id,
                username=self.eway_username,
                password=self.eway_password,
                url=self.rebill_url,
            )
            # CustomerDetails : To create rebill Customer
            customer_detail = rebillClient.client.factory.create("CustomerDetails")
            self.add_customer_details(credit_card, customer_detail, options)
            '''
                # Create Rebill customer and retrieve customer rebill ID.
            '''
            rebill_customer_response = rebillClient.create_rebill_customer(customer_detail)

            # Handler error in create_rebill_customer response
            if rebill_customer_response.ErrorSeverity:
                transaction_was_unsuccessful.send(sender=self,
                                                  type="recurringCreateRebill",
                                                  response=rebill_customer_response)
                error_response = rebill_customer_response
                raise

            rebile_customer_id = rebill_customer_response.RebillCustomerID
            '''
                For Each rebill profile
                # Create Rebill events using rebill customer ID and customer rebill details.
            '''
            rebill_event_response_list = []
            for each_rebill_profile in options.get("customer_rebill_details", []):
                rebill_detail = rebillClient.client.factory.create("RebillEventDetails")
                self.add_rebill_details(rebill_detail, rebile_customer_id, credit_card, each_rebill_profile)

                rebill_event_response = rebillClient.create_rebill_event(rebill_detail)

                # Handler error in create_rebill_event response
                if rebill_event_response.ErrorSeverity:
                    transaction_was_unsuccessful.send(sender=self,
                                                      type="recurringRebillEvent",
                                                      response=rebill_event_response)
                    error_response = rebill_event_response
                    raise

                rebill_event_response_list.append(rebill_event_response)

            transaction_was_successful.send(sender=self,
                                            type="recurring",
                                            response=rebill_event_response_list)
        except Exception as e:
            error_response['exception'] = e
            return {"status": "Failure", "response": error_response}

        return {"status": "SUCCESS", "response": rebill_event_response_list}
Beispiel #2
0
    def recurring(self, credit_card_details, options=None):
        """
            Recurring Payment Implementation using eWay recurring API (http://www.eway.com.au/developers/api/recurring)

            Input Parameters:
                ( Please find the details here in this Gist: https://gist.github.com/df67e02f7ffb39f415e6 )
                credit_card   :    Customer Credit Card details
                options       :    Customer and Recurring Payment details

            Output Dict:
                status: 'SUCCESS' or 'FAILURE'
                response : Response list of rebill event request in order of provided input
                           in options["customer_rebill_details"] list.
        """
        error_response = {}
        try:
            if not options:
                error_response = {"reason": "Not enough information Available!"}
                raise

            """
                # Validate Entered credit card details.
            """
            credit_card = CreditCard(**credit_card_details)
            if not self.validate_card(credit_card):
                raise InvalidCard("Invalid Card")

            rebillClient = RebillEwayClient(
                customer_id=self.customer_id,
                username=self.eway_username,
                password=self.eway_password,
                url=self.rebill_url,
            )
            # CustomerDetails : To create rebill Customer
            customer_detail = rebillClient.client.factory.create("CustomerDetails")
            self.add_customer_details(credit_card, customer_detail, options)
            """
                # Create Rebill customer and retrieve customer rebill ID.
            """
            rebill_customer_response = rebillClient.create_rebill_customer(customer_detail)

            # Handler error in create_rebill_customer response
            if rebill_customer_response.ErrorSeverity:
                transaction_was_unsuccessful.send(sender=self,
                                                  type="recurringCreateRebill",
                                                  response=rebill_customer_response)
                error_response = rebill_customer_response
                raise

            rebile_customer_id = rebill_customer_response.RebillCustomerID
            """
                For Each rebill profile
                # Create Rebill events using rebill customer ID and customer rebill details.
            """
            rebill_event_response_list = []
            for each_rebill_profile in options.get("customer_rebill_details", []):
                rebill_detail = rebillClient.client.factory.create("RebillEventDetails")
                self.add_rebill_details(rebill_detail, rebile_customer_id, credit_card, each_rebill_profile)

                rebill_event_response = rebillClient.create_rebill_event(rebill_detail)

                # Handler error in create_rebill_event response
                if rebill_event_response.ErrorSeverity:
                    transaction_was_unsuccessful.send(sender=self,
                                                      type="recurringRebillEvent",
                                                      response=rebill_event_response)
                    error_response = rebill_event_response
                    raise

                rebill_event_response_list.append(rebill_event_response)

            transaction_was_successful.send(sender=self,
                                            type="recurring",
                                            response=rebill_event_response_list)
        except Exception as e:
            error_response['exception'] = e
            return {"status": "Failure", "response": error_response}

        return {"status": "SUCCESS", "response": rebill_event_response_list}