Esempio n. 1
0
def enable_feature(request, feature, hook=None):
    from subscriptions.models import FeaturesManager
    shop = request.shop
    
    (feature_name, feature_description) = FeaturesManager.get_feature_description(feature)
    feature_price = FeaturesManager.get_feature_price(shop, feature)
    credit_card_info = True
    masked_number = "xxx"
    card_type = "---"
    expired = False
    try:
        billing_info = shop.billing_info()
        masked_number = billing_info.credit_card()['masked_number']
        card_type = billing_info.credit_card()['card_type']
        expired = billing_info.credit_card()['expired']
    except:
        credit_card_info = False
    
    params = {'credit_card_info': credit_card_info, 
              'feature_id': feature, 
              'feature_name': feature_name, 
              'feature_description': feature_description, 
              'feature_price': feature_price, 
              'masked_number': masked_number, 
              'card_type': card_type,
              'expired': expired }
    
    return render_to_response("store_admin/enable_feature.html", params, RequestContext(request))
Esempio n. 2
0
def enable_feature(request, feature, hook=None):
    from subscriptions.models import FeaturesManager
    shop = request.shop

    (feature_name,
     feature_description) = FeaturesManager.get_feature_description(feature)
    feature_price = FeaturesManager.get_feature_price(shop, feature)
    credit_card_info = True
    masked_number = "xxx"
    card_type = "---"
    expired = False
    try:
        billing_info = shop.billing_info()
        masked_number = billing_info.credit_card()['masked_number']
        card_type = billing_info.credit_card()['card_type']
        expired = billing_info.credit_card()['expired']
    except:
        credit_card_info = False

    params = {
        'credit_card_info': credit_card_info,
        'feature_id': feature,
        'feature_name': feature_name,
        'feature_description': feature_description,
        'feature_price': feature_price,
        'masked_number': masked_number,
        'card_type': card_type,
        'expired': expired
    }

    return render_to_response("store_admin/enable_feature.html", params,
                              RequestContext(request))
Esempio n. 3
0
def ajax_do_charge(request, feature):
    from payments.gateways.braintreegw import BraintreeGateway
    from subscriptions.models import FeaturesManager, FeaturePayment 
    from django.conf import settings
    
    success = False
    shop = request.shop
    gw = BraintreeGateway(settings.MERCHANT_ID, settings.PUBLIC_KEY, settings.PRIVATE_KEY)
    
    #This is token asociated to the subscription, we will use it to charge the feature
    token = shop.subscription().extra_data()[7]        
    #Try to charge the feature against braintree
    price = FeaturesManager.get_feature_price(shop, feature)
    result = gw.charge_purchase(token, price)
    
    admin_email = shop.marketplace.contact_email
    if result.is_success:
        status = result.transaction.status
        credit_card = "%s - %s******%s" % (result.transaction.credit_card[u'card_type'], result.transaction.credit_card[u'bin'], result.transaction.credit_card[u'last_4'])
        txn_id = result.transaction.id
        if status == 'authorized':
            logging.info("Transaction <id=%s> was successfully authorized!!" % (txn_id))
            submit = gw.submit_for_settlement(txn_id)
            message = None
            if submit.is_success:                
                message = "Shop: %s\nFeature: %s\nPrice: $ %s\nCredit Card: %s\nTransaction ID: %s\nTransaction Status: %s\n" % (shop, feature, price, credit_card, txn_id, status)
                logging.info(message)
            else:
                message = "WARNING: Transaction<id=%s> was successfully authorized but could not be submited for settlement. Try it manually via braintree admin site" % txn_id
                logging.critical(message)
            send_mail("Featured Successfully Purchased!", "\nWe have enabled the %s feature in your %s shop.\n\nWe collected $%s from your %s credit card account.\n\nThanks, %s" % (feature, shop, price, credit_card, shop.marketplace), settings.EMAIL_FROM, [shop.admin.email], True)
            send_mail("%s purchased the %s feature" % (shop, feature), message, settings.EMAIL_FROM, [mail for (name, mail) in settings.STAFF]+[admin_email], True)
        else:
            logging.critical("Transaction<id=%s> status is %s. Can't submit for settlement if status != authorized" % (txn_id, status))
        success = True
    else:
        success = False
        
    if success:
        payment = FeaturePayment(shop=shop)
        payment.transaction_id = txn_id
        payment.price = price
        payment.feature = feature
        payment.save()
        FeaturesManager.set_feature_enabled(shop, feature)
        resp = {
            'status': 'success',
            'txn_id': txn_id
        }
        return HttpResponse(simplejson.dumps(resp), mimetype="application/json")
    
    logging.critical("Feature could not be charged :(")
    
    for error in result.errors.deep_errors:
        logging.critical("Gateway Error Found > code=%s, msg=%s" % (error.code, error.message))
    
    message = ""
    if status == "processor_declined":
        message = "Reason: Processor declined the transaction<id=%s>. Error code %s - %s" % (result.transaction.id, result.transaction.processor_response_code, result.transaction.processor_response_text)
    elif status == "gateway_rejected":
        message = "Reason: Gateway rejected the transaction<id=%s>. Error on %s" % (result.transaction.id, result.transaction.gateway_rejection_reason)
    else:
        message = "Reason: transaction<id=%s> status is %s!. We have no more info about this status. Please check braintree admin console." % (status, result.transaction.id)
    
    logging.critical(message)
    send_mail("%s tried but failed to purchase the %s feature" % (shop, feature), message, settings.EMAIL_FROM, [mail for (name, mail) in settings.STAFF]+[admin_email], True)    
    return HttpResponseServerError()
Esempio n. 4
0
def ajax_do_charge(request, feature):
    from payments.gateways.braintreegw import BraintreeGateway
    from subscriptions.models import FeaturesManager, FeaturePayment
    from django.conf import settings

    success = False
    shop = request.shop
    gw = BraintreeGateway(settings.MERCHANT_ID, settings.PUBLIC_KEY,
                          settings.PRIVATE_KEY)

    #This is token asociated to the subscription, we will use it to charge the feature
    token = shop.subscription().extra_data()[7]
    #Try to charge the feature against braintree
    price = FeaturesManager.get_feature_price(shop, feature)
    result = gw.charge_purchase(token, price)

    admin_email = shop.marketplace.contact_email
    if result.is_success:
        status = result.transaction.status
        credit_card = "%s - ***********%s" % (
            result.transaction.credit_card[u'card_type'],
            result.transaction.credit_card[u'last_4'])
        txn_id = result.transaction.id
        if status == 'authorized':
            logging.info("Transaction <id=%s> was successfully authorized!!" %
                         (txn_id))
            submit = gw.submit_for_settlement(txn_id)
            message = None
            if submit.is_success:
                message = "Shop: %s\nFeature: %s\nPrice: $ %s\nCredit Card: %s\nTransaction ID: %s\nTransaction Status: %s\n" % (
                    shop, feature, price, credit_card, txn_id, status)
                logging.info(message)
            else:
                message = "WARNING: Transaction<id=%s> was successfully authorized but could not be submited for settlement. Try it manually via braintree admin site" % txn_id
                logging.critical(message)

            mail = EmailMessage(
                subject="Featured Successfully Purchased!",
                body=
                "\nWe have enabled the %s feature in your %s shop.\n\nWe collected $%s from your %s credit card account.\n\nThanks, %s"
                % (feature, shop, price, credit_card, shop.marketplace),
                from_email=settings.EMAIL_FROM,
                to=[shop.admin.email],
                headers={
                    'X-SMTPAPI': '{\"category\": \"Featured Purchased\"}'
                })
            mail.send(fail_silently=True)
            #            send_mail("Featured Successfully Purchased!", "\nWe have enabled the %s feature in your %s shop.\n\nWe collected $%s from your %s credit card account.\n\nThanks, %s" % (feature, shop, price, credit_card, shop.marketplace), settings.EMAIL_FROM, [shop.admin.email], True)

            mail = EmailMessage(
                subject="%s purchased the %s feature" % (shop, feature),
                body=message,
                from_email=settings.EMAIL_FROM,
                to=[mail for (name, mail) in settings.STAFF] + [admin_email],
                headers={
                    'X-SMTPAPI': '{\"category\": \"Featured Purchased\"}'
                })
            mail.send(fail_silently=True)


#            send_mail("%s purchased the %s feature" % (shop, feature), message, settings.EMAIL_FROM, [mail for (name, mail) in settings.STAFF]+[admin_email], True)
        else:
            logging.critical(
                "Transaction<id=%s> status is %s. Can't submit for settlement if status != authorized"
                % (txn_id, status))
        success = True
    else:
        success = False

    if success:
        payment = FeaturePayment(shop=shop)
        payment.transaction_id = txn_id
        payment.price = price
        payment.feature = feature
        payment.save()
        FeaturesManager.set_feature_enabled(shop, feature)
        resp = {'status': 'success', 'txn_id': txn_id}
        return HttpResponse(simplejson.dumps(resp),
                            mimetype="application/json")

    logging.critical("Feature could not be charged :(")

    for error in result.errors.deep_errors:
        logging.critical("Gateway Error Found > code=%s, msg=%s" %
                         (error.code, error.message))

    message = ""
    if status == "processor_declined":
        message = "Reason: Processor declined the transaction<id=%s>. Error code %s - %s" % (
            result.transaction.id, result.transaction.processor_response_code,
            result.transaction.processor_response_text)
    elif status == "gateway_rejected":
        message = "Reason: Gateway rejected the transaction<id=%s>. Error on %s" % (
            result.transaction.id, result.transaction.gateway_rejection_reason)
    else:
        message = "Reason: transaction<id=%s> status is %s!. We have no more info about this status. Please check braintree admin console." % (
            status, result.transaction.id)

    logging.critical(message)

    mail = EmailMessage(
        subject="%s tried but failed to purchase the %s feature" %
        (shop, feature),
        body=message,
        from_email=settings.EMAIL_FROM,
        to=[mail for (name, mail) in settings.STAFF] + [admin_email],
        headers={'X-SMTPAPI': '{\"category\": \"Error\"}'})
    mail.send(fail_silently=True)
    #    send_mail("%s tried but failed to purchase the %s feature" % (shop, feature), message, settings.EMAIL_FROM, [mail for (name, mail) in settings.STAFF]+[admin_email], True)

    return HttpResponseServerError()