def process_refund_request(response, amount): """ utility function to perform PayPal refund """ # call PayPal driver and perform the relevant PayPal API method to refund the money driver = PayPal() result = driver.RefundTransaction(response.trans_id, refundtype="Partial", amount=str(amount), currency=response.currencycode) # persist the response to the db with PayPalResponse instance paypal_response = PayPalResponse() paypal_response.fill_from_response(driver.GetRefundResponse(), action="Refund") paypal_response.status = PayPalResponse.get_cancel_status() if result: # Amount refunded successfully. paypal_response.payment_received = True paypal_response.save() return True, paypal_response else: # Amount charged could not be refunded successfully. Note that # the paypal_response is going to be saved paypal_response.error = _(driver.refundtransactionerror) paypal_response.save() return False, paypal_response
def process_payment_request(amount, currency, token, payerid): """ utility function to perform PayPal payment """ # call PayPal driver and perform the relevant PayPal API method to charge the money driver = PayPal() result = driver.DoExpressCheckoutPayment(currency=currency, amount=str(amount), token=token, payerid=payerid) # persist the response to the db with PayPalResponse instance paypal_response = PayPalResponse() paypal_response.fill_from_response(driver.GetPaymentResponse()) paypal_response.status = PayPalResponse.get_default_status() if result: # Amount charged successfully. paypal_response.payment_received = True paypal_response.save() return True, paypal_response else: # Amount charged could not be charged successfully. Note that # the paypal_response is going to be saved. paypal_response.error = _(driver.doexpresscheckoutpaymenterror) paypal_response.save() return False, paypal_response
def process(request, order_form, order): """ Raise cartridge.shop.checkout.CheckoutError("error message") if payment is unsuccessful. - DoDirectPayment(self, acct, expdate, cvv2, cardtype, first_name, last_name, amount, currency = "USD", **kwargs) returns True or False """ acct = order_form.cleaned_data["card_number"].replace(" ", "") expdate = order_form.cleaned_data["card_expiry_month"] + order_form.cleaned_data["card_expiry_year"] cvv2 = order_form.cleaned_data["card_ccv"] if order_form.cleaned_data["card_type"] == "Mastercard": cardtype = "MasterCard" else: cardtype = order_form.cleaned_data["card_type"] amount = Decimal(order.total) try: ipaddress = request.META["HTTP_X_FORWARDED_FOR"] except: ipaddress = request.META["REMOTE_ADDR"] card_name = order_form.cleaned_data["card_name"] first_name = card_name.split()[:-1] last_name = card_name.split()[-1] street = order_form.cleaned_data["billing_detail_street"] city = order_form.cleaned_data["billing_detail_city"] state = order_form.cleaned_data["billing_detail_state"] postcode = order_form.cleaned_data["billing_detail_postcode"] country = order_form.cleaned_data["billing_detail_country"] email = order_form.cleaned_data["billing_detail_email"] s_first_name = order_form.cleaned_data["shipping_detail_first_name"] s_last_name = order_form.cleaned_data["shipping_detail_last_name"] shiptoname = s_first_name + " " + s_last_name s_street = order_form.cleaned_data["shipping_detail_street"] s_city = order_form.cleaned_data["shipping_detail_city"] s_state = order_form.cleaned_data["shipping_detail_state"] s_postcode = order_form.cleaned_data["shipping_detail_postcode"] s_country = order_form.cleaned_data["shipping_detail_country"] s_phone = order_form.cleaned_data["shipping_detail_phone"] invnum = str(order.id) p = PayPal() result = p.DoDirectPayment( acct, expdate, cvv2, cardtype, first_name, last_name, amount, currency="USD", email=email, ipaddress=ipaddress, street=street, city=city, state=state, zip=postcode, countrycode=country, invnum=invnum, shiptoname=shiptoname, shiptostreet=s_street, shiptocity=s_city, shiptostate=s_state, shiptozip=s_postcode, shiptocountry=s_country, shiptophonenum=s_phone, ) if result == True: response = PayPalResponse() response.fill_from_response(p.GetPaymentResponse, action="Payment") response.status = PayPalResponse.get_default_status() response.save() order.status = "2" order.save() else: raise CheckoutError(p.apierror)
def process_payment_request(amount, currency, token, payerid): driver = PayPal() result = driver.DoExpressCheckoutPayment(currency = currency, amount = str(amount), token = token, payerid = payerid) paypal_response = PayPalResponse() paypal_response.fill_from_response(driver.GetPaymentResponse()) paypal_response.status = PayPalResponse.get_default_status() if result == True: paypal_response.payment_received = True paypal_response.save() return True, paypal_response else: paypal_response.error = _(driver.doexpresscheckoutpaymenterror) paypal_response.save() return False, paypal_response
def process_refund_request(response, amount): driver = PayPal() result = driver.RefundTransaction(response.trans_id, refundtype = "Partial", amount = str(amount), currency = response.currencycode) # persist the response to the db with PayPalResponse instance paypal_response = PayPalResponse() paypal_response.fill_from_response(driver.GetRefundResponse(), action = "Refund") paypal_response.status = PayPalResponse.get_cancel_status() if result == True: paypal_response.payment_received = True paypal_response.save() return True, paypal_response else: paypal_response.error = _(driver.refundtransactionerror) paypal_response.save() return False, paypal_response
def process_payment_request(amount, currency, token, payerid): """ utility function to perform PayPal payment """ ################# # BEGIN ROUTINE # ################# # call PayPal driver and perform the relevant PayPal API method to charge the money driver = PayPal() result = driver.DoExpressCheckoutPayment(currency = currency, amount = str(amount), token = token, payerid = payerid) # persist the response to the db with PayPalResponse instance paypal_response = PayPalResponse() paypal_response.fill_from_response(driver.GetPaymentResponse()) paypal_response.status = PayPalResponse.get_default_status() if result == True: # Amount charged successfully. paypal_response.payment_received = True paypal_response.save() return True, paypal_response else: # Amount charged could not be charged successfully. Note that # the paypal_response is going to be saved. paypal_response.error = _(driver.doexpresscheckoutpaymenterror) paypal_response.save() return False, paypal_response