Exemple #1
0
  def create_hook(self, event_types):
    '''
    Create a valid hook for the given event types
    Cleanup previous invalid hooks
    '''
    # List hooks
    ctx = paymill.PaymillContext(settings.PAYMILL_SECRET)
    webhook_service = ctx.get_webhook_service()
    hooks = webhook_service.list()

    # Check hooks
    valid = False
    for hook in hooks.data:
      # Only email hooks
      if 'email' not in hook:
        continue

      # Only consider hooks for current address
      if hook['email'] != settings.PAYMILL_HOOK_EMAIL:
        continue

      if hook['event_types'] == event_types and hook['active']:
        valid = True
        print 'Hook is still valid', hook
      else:
        # Cleanup old hooks
        from collections import namedtuple
        DummyHook = namedtuple('DummyHook', 'id')
        h = DummyHook(id=hook['id'])
        webhook_service.remove(h)

    # Create a new valid hook
    if not valid:
      hook = webhook_service.create_email(email=settings.PAYMILL_HOOK_EMAIL, active=True, event_types=event_types)
      print 'Created hook %s' % hook
Exemple #2
0
    def sync_paymill(self):
        '''
    Create user on paymill
    '''
        # Check we don't already have an id
        if self.paymill_id:
            raise Exception('Already have a paymill id')

        # Get paymill service
        paymill_name = '#%d %s %s' % (self.id, self.first_name, self.last_name)
        ctx = paymill.PaymillContext(settings.PAYMILL_SECRET)
        service = ctx.get_client_service()
        client = service.create(email=self.email, description=paymill_name)

        # Save paymill id
        self.paymill_id = client.id
        self.save()

        return client
Exemple #3
0
    def sync_paymill(self):
        '''
    Sync the offer on paymill
    '''
        if self.paymill_id:
            raise Exception('Already a paymill id')

        # Prepare data
        data = {
            'name': self.name,
            'amount': self.amount_cents,
            'currency': self.currency,
            'interval': self.interval,
        }

        # Create the subscription
        ctx = paymill.PaymillContext(settings.PAYMILL_SECRET)
        service = ctx.get_offer_service()
        offer = service.create(**data)

        # Save the new paymill id
        self.paymill_id = str(offer['id'])
        self.save()
Exemple #4
0
                already_skipped = "false"
                for row_2 in VIP_model_store_credit:
                    if now.day >= 1 and now.day <= 10:
                        if date_VIP_2[1] == str(now.month -
                                                1) and date_VIP_2[0] == str(
                                                    now.year) and (
                                                        row_2[6] == "true"
                                                        or row_2[4] != ""):
                            already_skipped = "true"

                if abgebucht == "false" and already_skipped == "false":
                    if row[56] != "klarna" and row[56] != "paypal" and row[
                            56] != "sofort":
                        print("transaction_id")

                        paymill_context = paymill.PaymillContext(
                            '82239adeff57ef5d51ec2e5d11fd915d')
                        transaction_service = paymill_context.get_transaction_service(
                        )
                        transaction_with_client_and_payment = transaction_service.create_with_payment_id(
                            payment_id=row[56],
                            amount=2995,
                            currency="EUR",
                            description="Darling Lace VIP Store Credit: " +
                            str(now.month) + "/" + str(now.year),
                            client_id=row[50])

                        class Object(object):
                            pass

                        transaction_key = Object()
                        transaction_key.id = transaction_with_client_and_payment[
Exemple #5
0
    def create_subscription(self, token, user, club=None):
        '''
    Create a payment for current offer
    with specified token from JS form
    and optional client
    Then link it to a subscription
    '''
        if not user.paymill_id:
            raise Exception('Missing client paymill id')

        # Check there is not already a subscription for this user
        if self.target == 'athlete' and self.subscriptions.filter(
                user=user).exists():
            raise Exception('Already a subscription for this offer & user')

        # Same check but for clubs
        if self.target == 'club':
            if not club:
                raise Exception('Missing club instance')
            if club.subscriptions.filter(user=user).exists():
                raise Exception('Already a subscription for this offer & user')

        # Prepare data for payment
        data = {
            'client_id': user.paymill_id,
            'token': token,
        }

        # Create the transaction in Paymill
        ctx = paymill.PaymillContext(settings.PAYMILL_SECRET)
        service = ctx.get_payment_service()
        payment = service.create(**data)

        # Prepare data for subscription
        data = {
            'offer_id': self.paymill_id,
            'payment_id': payment.id,
            'client_id': user.paymill_id,
            'name': self.name,
        }

        # Paymill subscription service
        ctx = paymill.PaymillContext(settings.PAYMILL_SECRET)
        service = ctx.get_subscription_service()

        if self.target == 'athlete':
            # Remaining free days ?
            try:
                sub = user.subscriptions.get(offer__slug='athlete_welcome',
                                             status='active')
                if not sub.end:
                    raise Exception('Missing end date')
                start = sub.end  # Paying subscription start at the end of welcome

            except PaymentSubscription.DoesNotExist:
                logger.warn('No welcome subscription for user %s' % user)
                start = datetime.now()
            data['start_at'] = time.mktime(start.timetuple())

            # Create the subscription in Paymill
            subscription = service.create_with_offer_id(**data)

            # Save the subscription as awaiting validation
            user.subscriptions.create(offer=self,
                                      paymill_id=subscription.id,
                                      start=start)

        if self.target == 'club' and club:
            # Create the subscription in Paymill
            subscription = service.create_with_offer_id(**data)

            # Save the subscription as awaiting validation
            start = datetime.now()
            club.subscriptions.create(offer=self,
                                      paymill_id=subscription.id,
                                      start=start)

        return subscription
            already_skipped = "false"
            print("check_month_VIP")
            for row_2 in VIP_model_store_credit:
                if now.day >= 1 and now.day <= 10:
                    if row_2[0][4:6] == str(now.month -
                                            1) and row_2[0][0:4] == str(
                                                now.year) and (
                                                    row_2[6] == "true"
                                                    or row_2[4] != ""):
                        print("true")
                        already_skipped = "true"

            if abgebucht == "false" and already_skipped == "false":
                print("transaction_id")

                paymill_context = paymill.PaymillContext(
                    '5ccd454aa30b1614e44193f740762a52')
                transaction_service = paymill_context.get_transaction_service()
                transaction_with_client_and_payment = transaction_service.create_with_payment_id(
                    payment_id=row[56],
                    amount=2995,
                    currency="EUR",
                    description="Darling Lace VIP Store Credit: " +
                    str(now.month) + "/" + str(now.year),
                    client_id=row[50])
                print(transaction_with_client_and_payment["id"])

                print("transaction_janu")

                class Object(object):
                    pass