Ejemplo n.º 1
0
def create(request, recipient_id, entity_id, amount):
    # Check Parameter Value Types
    recipient_id, success = validate_int(recipient_id)
    if not success:
        return cors_response(
            build_error(API_ERROR.INVALID_PARAMETER, parameter='recipient_id'))

    entity_id, success = validate_int(entity_id)
    if not success:
        return cors_response(
            build_error(API_ERROR.INVALID_PARAMETER, parameter='entity_id'))

    amount, success = validate_float(amount)
    if not success:
        return cors_response(
            build_error(API_ERROR.INVALID_PARAMETER, parameter='amount'))
    if amount <= 0:
        return cors_response(
            build_error(API_ERROR.INVALID_PARAMETER, parameter='amount'))

    # Get entity
    entity = Entity.objects.filter(pk=entity_id)
    if len(entity) != 1:
        return cors_response(
            build_error(API_ERROR.INVALID_PARAMETER, parameter='entity_id'))
    entity = entity[0]

    # Get recipient from entity
    # (this will also confirm the entity and recipient are linked)
    recipient = entity.recipient.filter(pk=recipient_id)
    if len(recipient) != 1:
        return cors_response(
            build_error(API_ERROR.INVALID_PARAMETER, parameter='recipient_id'))
    recipient = recipient[0]

    payee = recipient.payee
    if payee is None or payee.userservice is None:
        return cors_response(
            build_error(API_ERROR.DONATION.NO_PAYEE))

    # Create donation
    _, checkout_url = payment.registry[payee.userservice.service].donation_create(
        entity, recipient, payee, amount,
        base_url=build_url(request),
        redirect_name='donation-confirm',
        callback_name='callback-wepay-checkout'
    )

    # Make the checkout_url absolute
    checkout_url = urlparse.urljoin(build_url(request), checkout_url)

    if checkout_url:
        return cors_response(simplejson.dumps({
            'checkout_url': checkout_url,
            'success': True
        }))
    return cors_response(build_error(API_ERROR.DONATION.SERVICE_FAILED))
Ejemplo n.º 2
0
def checkout(request, donation_token):
    donation = Donation.objects.filter(token=donation_token)

    if len(donation) == 1:
        donation = donation[0]

        if donation.state == Donation.STATE_EXPIRED:
            return HttpResponse('Donation has expired')
        elif donation.state != Donation.STATE_NEW:
            return HttpResponse('Donation has already been processed')

        platform = payment.registry[donation.payee.userservice.service]

        # Only accept platforms with DONATION_FORM as 'donation_type'
        if (platform.Meta.donation_type == payment.DONATION_FORM and
                platform.Meta.donation_form is not None):

            return render_to_response('donation/checkout.html',
                                      context_instance=RequestContext(request, {
                                          'form': platform.Meta.donation_form(
                                              donation,
                                              build_url(
                                                  request,
                                                  reverse(
                                                      'donation-confirm',
                                                      args=[donation_token]
                                                  )
                                              )
                                          )
                                      }))
        else:
            return HttpResponse("Payment Platform doesn't require hosted checkouts")
    else:
        return HttpResponse("Unable to find your donation")
Ejemplo n.º 3
0
def payee_add_wepay(request):
    if not 'code' in request.GET:
        return redirect(reverse('account-payee-add'))

    try:
        created, service = payment.registry[Service.SERVICE_WEPAY].service_create(
            request.user,
            redirect_uri=build_url(request, reverse('account-payee-add-wepay')),
            code=request.GET['code']
        )
        if service:
            if created:
                return redirect(reverse('account-payee-add'))
            else:
                return error_redirect('ALREADY_AUTHORIZED')
        else:
            return error_redirect('UNKNOWN_AUTHORIZATION_ERROR')
    except WePayError, e:
        print e
        if e.type == 'access_denied':
            return redirect(payment.registry[Service.SERVICE_WEPAY].get_oauth_url(
                build_url(request, reverse('account-payee-add-wepay'))
            ))
Ejemplo n.º 4
0
    def build_info_dict(self, request=None):
        platforms = {}
        for key, platform in self.platforms.items():
            if isinstance(platform, PaymentPlatform):
                # Build a dictionary of the platform Meta
                platform_info = {}
                for attr_key, attr_value in platform.Meta.__dict__.items():
                    if not attr_key.startswith('__') and not attr_key.endswith('__'):
                        platform_info[attr_key] = attr_value

                # Build the OAuth url if the platform uses OAuth
                if platform.Meta.authorization_type == AUTHORIZATION_OAUTH:
                    if request is None:
                        raise TypeError()
                    platform_info['oauth_url'] = platform.get_oauth_url(
                        build_url(request, reverse('account-payee-add-' + key))
                    )

                platforms[key] = platform_info
        return platforms