Exemplo n.º 1
0
 def next_screen(self, current_input):
     if current_input not in [1, 2]:
         return self.error_screen(errors=["Invalid Input"])
     if current_input == 1:
         return get_screen('choose_payment_method',
                           data={
                               'item_id': self.data['item_id'],
                               'complementary': self.data['complementary']
                           })
     if current_input == 2:
         return get_screen('choose_provider')
Exemplo n.º 2
0
 def next_screen(self, current_input):
     if current_input not in [1, 2]:
         return self.error_screen(errors=["Invalid Input.Try again"])
     if current_input == 1:
         return get_screen('choose_confirmation_status',
                           data={
                               'item_id': self.data['item_id'],
                               'complementary': False
                           })
     if current_input == 2:
         # return get_screen('finish_no_cylinder')
         return get_screen('choose_cylinder_package',
                           data={
                               'item_id': self.data['item_id'],
                           })
Exemplo n.º 3
0
 def next_screen(self, current_input):
     if current_input not in [1, 2]:
         return self.error_screen(errors=["Invalid Input"])
     if current_input == 1:
         return get_screen('finish_mpesa',
                           data={
                               'item_id': self.data['item_id'],
                               'complementary': self.data['complementary']
                           })
     if current_input == 2:
         return get_screen('finish_order',
                           data={
                               'item_id': self.data['item_id'],
                               'complementary': self.data['complementary']
                           })
Exemplo n.º 4
0
 def next_screen(self, current_input: int):
     try:
         brand = Brand.objects.get_by_position(current_input)
     except Exception:
         return self.error_screen(
             errors=['Invalid option.Check and try again'])
     return get_screen('choose_cylinder', data={'provider_id': brand.id})
Exemplo n.º 5
0
def index(request):
    if request.method == 'POST':
        session_id = request.POST.get('sessionId')
        service_code = request.POST.get('serviceCode')
        phone_number = request.POST.get('phoneNumber')
        text = request.POST.get('text')

        # get buyer in the system
        buyer = get_buyer(phone_number)
        # initialize the ussd session
        session = USSDSession(session_id, context={'buyer': buyer})
        # load the default screen
        if text == "":
            # empty string means user has not chosen
            # show the default start screen
            screen = get_screen('choose_provider')
            return session.render(screen)
        else:
            # get current_text
            current_input = text.split("*")[-1]
            # get current session
            current_screen: Screen = session.current_screen
            try:
                current_input = int(current_input)
            except ValueError:
                session.render(current_screen)
            # get the next screen
            next_screen = current_screen.next_screen(current_input)
            return session.render(next_screen)
    return HttpResponse("Invalid HTTP method", status=403)
Exemplo n.º 6
0
    def next_screen(self, current_input):
        """get sender option or talk to us request """
        if current_input == 0:
            return get_screen('finish_no_cylinder')

        try:
            item = Item.objects.get(id=self.data['item_id'])
            complementary_item = item.complementary_items.get_by_position(
                current_input)
        except Exception:
            return self.error_screen(
                errors=['Invalid option.Check and try again'])
        return get_screen('choose_confirmation_status',
                          data={
                              'item_id': complementary_item.id,
                              'complementary': True
                          })
Exemplo n.º 7
0
 def next_screen(self, current_input: int):
     """shows ownership status of the screen"""
     # check for errors in ownership and go to the next step
     # which is ownership status
     try:
         provider = Brand.objects.get(id=self.data['provider_id'])
         item = Item.objects.get_by_position(current_input,
                                             queryset=provider.items.all())
     except Exception:
         return self.error_screen(
             errors=['Invalid option.Check and try again'])
     return get_screen('ownership_status', data={'item_id': item.id})