def refund(self): if self.payment.state_actual.state == 'PA': if self.is_manual_payment(): pass if self.is_paypal_payment(): from payments.gateways.paypal import PayPalGateway from payments.models import PayPalShopSettings, PayPalTransaction paypal_gw = PayPalGateway(username=settings.PAYPAL_USERNAME, password=settings.PAYPAL_PASSWORD, sign=settings.PAYPAL_SIGNATURE, debug=settings.PAYPAL_DEBUG) try: txn = PayPalTransaction.objects.filter(sell=self).get() paypal_gw.RefundTransaction( txn.transaction_id, 'Full', 'USD', self.total, "Programatic refund from shop admin") except PayPalTransaction.DoesNotExist: raise SellError( "PayPalTransaction not found. Refund can't be performed..." ) if self.is_google_checkout(): from payments.gateways.googlecheckout import GoogleCheckoutGateway, GoogleCheckoutOrder from payments.models import GoogleCheckoutShopSettings try: google_settings = GoogleCheckoutShopSettings.objects.filter( shop=self.shop).get() except GoogleCheckoutShopSettings.DoesNotExist: raise SellError( "Google Checkout Settings are disabled! Refund can't be performed" ) googlecheckout_gw = GoogleCheckoutGateway( google_settings.merchant_id, google_settings.merchant_key, debug=True) try: order = GoogleCheckoutOrder.objects.filter(sell=self).get() refund = googlecheckout_gw.refund_order( order.order_number, self.total, "Programatic refund from shop admin") except GoogleCheckoutOrder.DoesNotExist: raise SellError( "This sell it's not associated to any GoogleCheckoutOrder! Refund can't be performed" ) if self.is_braintree(): from payments.gateways.braintreegw import BraintreeGateway from payments.models import BrainTreeTransaction try: bt_txn = BrainTreeTransaction.objects.filter( sell=self).get() except BrainTreeTransaction.DoesNotExist: raise SellError( 'There is no Braintree transaction associated to this sell!' ) gw = BraintreeGateway(settings.MERCHANT_ID, settings.PUBLIC_KEY, settings.PRIVATE_KEY) refund = gw.refund_transaction(bt_txn.transaction_id) if not refund.is_success: message = "" if refund.transaction: code = refund.transaction.processor_response_code text = refund.transaction.processor_response_text message = "Refund Failed! %s.\[%s] %s" % ( refund.message, code, text) else: for error in refund.errors.deep_errors: txt = "attribute: %s, code: %s. %s" ( error.attribute, error.code, error.message) message += txt + "\n" raise SellError("Can't do refund. %s" % message) for item in self.sellitem_set.all(): # item.product.increase_qty(item.qty) item.product.activate() item.save() self.cancel = True self.save() self.payment.refunded() else: raise SellError( 'Can not refund this sell, your state is not paid.')
def checkout_confirm(request): from payments.gateways.googlecheckout import GoogleCheckoutGateway from payments.gateways.paypal import PayPalGateway from payments.gateways.braintreegw import BraintreeGateway from payments.models import GoogleCheckoutShopSettings, PayPalShopSettings, ManualPaymentShopSettings, BraintreeShopSettings #A list of payment method, each payment method know how to render as a link #payment_methods = request.shop.get_payment_methods() payment_buttons = [] #profile = request.user.get_profile() cart = request.cart shop = request.shop try: google_settings = GoogleCheckoutShopSettings.objects.filter(shop = shop).get() googlecheckout_gw = GoogleCheckoutGateway(google_settings.merchant_id, google_settings.merchant_key, debug=True) button = googlecheckout_gw.render_button(cart) payment_buttons.append(button) except GoogleCheckoutShopSettings.DoesNotExist: pass try: braintree_settings = BraintreeShopSettings.objects.filter(shop = shop).get() braintree_gw = BraintreeGateway(braintree_settings.merchant_id, braintree_settings.public_key, braintree_settings.private_key, ) button = braintree_gw.render_button(cart) payment_buttons.append(button) except BraintreeShopSettings.DoesNotExist: pass try: paypal_settings = PayPalShopSettings.objects.filter(shop = shop).get() paypal_gw = PayPalGateway(username=settings.PAYPAL_USERNAME, password=settings.PAYPAL_PASSWORD, sign=settings.PAYPAL_SIGNATURE, debug=settings.PAYPAL_DEBUG) button = paypal_gw.render_button() logging.critical(button) payment_buttons.append(button) except PayPalShopSettings.DoesNotExist: pass try: manual_payment_settings = ManualPaymentShopSettings.objects.filter(shop = shop) url = reverse("myshopping_checkout_manual_payment") if manual_payment_settings.count(): button = """ <div> <h3>Manual Payments</h3>\n <form name='manual_payment' action='%s' method='POST'>\n """ % url for idx, payment in enumerate(manual_payment_settings): input = '\t<input type="radio" name="manual_payment_id" checked="%d" value="%s"> %s </input><br/>\n' % (1 if idx == 0 else 0, payment.id, payment.name) button += input button += "<br/>" button += "<button class='primaryAction small awesome' type='submit'>Submit</button>\n" button += "</form>\n" button += "</div>" logging.debug(button) payment_buttons.append(button) except Exception, e: logging.error(e)
def refund(self): if self.payment.state_actual.state == 'PA': if self.is_manual_payment(): pass if self.is_paypal_payment(): from payments.gateways.paypal import PayPalGateway from payments.models import PayPalShopSettings, PayPalTransaction paypal_gw = PayPalGateway(username=settings.PAYPAL_USERNAME, password=settings.PAYPAL_PASSWORD, sign=settings.PAYPAL_SIGNATURE, debug=settings.PAYPAL_DEBUG) try: txn = PayPalTransaction.objects.filter(sell=self).get() paypal_gw.RefundTransaction(txn.transaction_id, 'Full', 'USD', self.total, "Programatic refund from shop admin") except PayPalTransaction.DoesNotExist: raise SellError("PayPalTransaction not found. Refund can't be performed...") if self.is_google_checkout(): from payments.gateways.googlecheckout import GoogleCheckoutGateway, GoogleCheckoutOrder from payments.models import GoogleCheckoutShopSettings try: google_settings = GoogleCheckoutShopSettings.objects.filter(shop = self.shop).get() except GoogleCheckoutShopSettings.DoesNotExist: raise SellError("Google Checkout Settings are disabled! Refund can't be performed") googlecheckout_gw = GoogleCheckoutGateway(google_settings.merchant_id, google_settings.merchant_key, debug=True) try: order = GoogleCheckoutOrder.objects.filter(sell=self).get() refund = googlecheckout_gw.refund_order(order.order_number, self.total, "Programatic refund from shop admin") except GoogleCheckoutOrder.DoesNotExist: raise SellError("This sell it's not associated to any GoogleCheckoutOrder! Refund can't be performed") if self.is_braintree(): from payments.gateways.braintreegw import BraintreeGateway from payments.models import BrainTreeTransaction try: bt_txn = BrainTreeTransaction.objects.filter(sell=self).get() except BrainTreeTransaction.DoesNotExist: raise SellError('There is no Braintree transaction associated to this sell!') gw = BraintreeGateway(settings.MERCHANT_ID, settings.PUBLIC_KEY, settings.PRIVATE_KEY) refund = gw.refund_transaction(bt_txn.transaction_id) if not refund.is_success: message = "" if refund.transaction: code = refund.transaction.processor_response_code text = refund.transaction.processor_response_text message = "Refund Failed! %s.\[%s] %s" % (refund.message, code, text) else: for error in refund.errors.deep_errors: txt = "attribute: %s, code: %s. %s" (error.attribute, error.code, error.message) message += txt + "\n" raise SellError("Can't do refund. %s" % message) for item in self.sellitem_set.all(): item.product.increase_qty(item.qty) item.product.activate() item.save() self.cancel = True self.save() self.payment.refunded() else: raise SellError('Can not refund this sell, your state is not paid.')
def checkout_confirm(request): from payments.gateways.googlecheckout import GoogleCheckoutGateway from payments.gateways.paypal import PayPalGateway from payments.gateways.braintreegw import BraintreeGateway from payments.models import GoogleCheckoutShopSettings, PayPalShopSettings, ManualPaymentShopSettings, BraintreeShopSettings #A list of payment method, each payment method know how to render as a link #payment_methods = request.shop.get_payment_methods() payment_buttons = [] #profile = request.user.get_profile() cart = request.cart shop = request.shop if not cart.is_available(): request.flash['message'] = 'Items not longer available: ' for item in cart.items_not_availables(): request.flash['message'] += item.product.title cart.remove_not_available_items() return HttpResponseRedirect(reverse('my_shopping')) try: google_settings = GoogleCheckoutShopSettings.objects.filter( shop=shop).get() googlecheckout_gw = GoogleCheckoutGateway(google_settings.merchant_id, google_settings.merchant_key, debug=True) button = googlecheckout_gw.render_button(cart) payment_buttons.append(button) except GoogleCheckoutShopSettings.DoesNotExist: pass try: braintree_settings = BraintreeShopSettings.objects.filter( shop=shop).get() braintree_gw = BraintreeGateway( braintree_settings.merchant_id, braintree_settings.public_key, braintree_settings.private_key, ) button = braintree_gw.render_button(cart, request) payment_buttons.append(button) except BraintreeShopSettings.DoesNotExist: pass try: paypal_settings = PayPalShopSettings.objects.filter(shop=shop).get() paypal_gw = PayPalGateway(username=settings.PAYPAL_USERNAME, password=settings.PAYPAL_PASSWORD, sign=settings.PAYPAL_SIGNATURE, debug=settings.PAYPAL_DEBUG) button = paypal_gw.render_button() payment_buttons.append(button) except PayPalShopSettings.DoesNotExist: pass try: manual_payment_settings = ManualPaymentShopSettings.objects.filter( shop=shop) url = reverse("myshopping_checkout_manual_payment") if manual_payment_settings.count(): button = """ <div> <h3>Manual Payments</h3>\n <form name='manual_payment' action='%s' method='POST'>\n """ % url for idx, payment in enumerate(manual_payment_settings): input = '\t<input type="radio" name="manual_payment_id" checked="%d" value="%s"> %s </input><br/>\n' % ( 1 if idx == 0 else 0, payment.id, payment.name) button += input button += "<br/>" button += "<button class='primaryAction small awesome' type='submit'>Submit</button>\n" button += "</form>\n" button += "</div>" logging.debug(button) payment_buttons.append(button) except Exception, e: logging.error(e)