Ejemplo n.º 1
0
def ipn_test(request, settings=None):
    """Manually triggers an IPN result"""
    from bursar.gateway.paypal_gateway.forms import IpnTestForm

    if not settings:
        raise GatewayError(
            'Paypal IPN needs settings, please put into your urls.')

    gateway = processor.PaymentProcessor(settings=settings)

    if request.method == "POST":
        data = request.POST.copy()
        form = IpnTestForm(data)
        if form.is_valid():
            log.debug('Doing an IPN test on %s', data)
            data = form.cleaned_data
            invoice = data['invoice']
            gross = data['amount']
            transaction_id = data['transaction']
            note = data['note']
            gateway.accept_ipn(invoice, gross, transaction_id, note)
    else:
        form = IpnTestForm()

    ctx = RequestContext(request, {
        'form': form,
    })

    return render_to_response('bursar/gateway/paypal_gateway/ipn_test.html',
                              ctx)
Ejemplo n.º 2
0
def ipn(request, settings=None):
    """PayPal IPN (Instant Payment Notification)
    Confirms that payment has been completed and marks invoice as paid.
    Adapted from IPN cgi script provided at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/456361"""

    if not settings:
        raise GatewayError(
            'Paypal IPN needs settings, please put into your urls.')

    gateway = processor.PaymentProcessor(settings=settings)

    sane = True

    if not request.method == "POST":
        log.warn("IPN request - no post data, ignoring.")
        sane = False

    else:
        data = request.POST.copy()
        if not gateway.confirm_ipn_data(data):
            sane = False

    if sane:
        status = data.get('payment_status', 'unknown')
        if status != "Completed":
            # We want to respond to anything that isn't a payment - but we won't insert into our database.
            log.info(
                "Ignoring IPN data for non-completed payment. Status is '%s'",
                status)
            sane = False

    if sane:
        invoice = data.get('invoice', '')
        if not invoice:
            invoice = data.get('item_number', '')

        if not invoice:
            log.info("No invoice # in data, aborting IPN")
            sane = False

    if sane:
        gross = data['mc_gross']
        txn_id = data['txn_id']
        note = data.get('memo', '')
        gateway.accept_ipn(invoice, gross, txn_id, note)

    return HttpResponse()
Ejemplo n.º 3
0
 def setUp(self):
     global SKIP_TESTS
     self.client = Client()
     if not SKIP_TESTS:
         settings = get_bursar_setting('PAYPAL_TEST', default_value={})
         settings['EXTRA_LOGGING'] = True
         if not settings:
             SKIP_TESTS = True
             raise GatewayError(NEED_SETTINGS)
         self.gateway = processor.PaymentProcessor(settings=settings)
         self.default_payment = {
             'ccv': '111',
             'card_number': '4111111111111111',
             'expire_month': 12,
             'expire_year': 2012,
             'card_type': 'visa'
         }
Ejemplo n.º 4
0
 def require_settings(self, *args):
     for arg in args:
         val = self.settings.get(arg, None)
         if not val:
             raise GatewayError('You must define a %s for the %s payment module.' % (arg, self.key))
Ejemplo n.º 5
0
 def require_file(self, fname, warning=None):
     if not os.path.isfile(fname):
         if not warning:
             warning="Cannot find file '%s'" % fname
         raise GatewayError(warning)
Ejemplo n.º 6
0
    def __init__(self, settings={}):
        working_settings = {
            'BUSINESS':
            '',  #required, your paypal email address
            # Currency code for Paypal transactions.
            'CURRENCY_CODE':
            'USD',

            #a named view where the customer will
            #be returned after a successful purchase
            'RETURN_ADDRESS':
            "PAYPAL_GATEWAY_ipn",

            # Accept real payments
            'LIVE':
            False,

            # use SSL for checkout
            'SSL':
            False,
            'LOCALE':
            'US',

            # Reattempt on fail
            'REATTEMPT':
            True,
            'LABEL':
            _('PayPal'),
            'EXTRA_LOGGING':
            False,
            'ENCRYPT':
            False,

            # Path to the public key from PayPal, get this at:
            # https://www.paypal.com/us/cgi-bin/webscr?cmd=_profile-website-cert'
            'PAYPAL_PUBKEY':
            "",

            # Path to your paypal private key
            'PRIVATE_KEY':
            "",

            # Path to your paypal public key
            'PUBLIC_KEY':
            "",

            # Your Cert ID, copied from the PayPal website after uploading your public key
            'PUBLIC_CERT_ID':
            "",
            'BUY_BUTTON_URL':
            'http://images.paypal.com/images/x-click-but01.gif',
            'SUBSCRIBE_BUTTON_URL':
            'https://www.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif',
            'TEST_BUY_BUTTON_URL':
            'https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif',
            'TEST_SUBSCRIBE_BUTTON_URL':
            "https://www.sandbox.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif"
        }
        working_settings.update(settings)

        super(PaymentProcessor, self).__init__('paypal', working_settings)
        self.require_settings("BUSINESS", "RETURN_ADDRESS")
        if self.settings['ENCRYPT']:
            self.require_settings("PAYPAL_PUBKEY", "PRIVATE_KEY", "PUBLIC_KEY",
                                  "PUBLIC_CERT_ID")
            self.paypalpubkey = self.settings["PAYPAL_PUBKEY"]
            self.localprikey = self.settings["PRIVATE_KEY"]
            self.localpubkey = self.settings["PUBLIC_KEY"]
            self.require_file(self.paypalpubkey)
            self.require_file(self.localpubkey)
            self.require_file(self.localprikey)
            try:
                import M2Crypto
            except ImportError:
                raise GatewayError(
                    'paypal_gateway: You must install M2Crypto to use an encrypted PayPal form.'
                )