def create_payment(booking, offerer, amount, author='test author', reimbursement_rule='remboursement à 100%', reimbursement_rate=Decimal(0.5), payment_message=None, payment_message_name=None, transaction_end_to_end_id=None, transaction_label='pass Culture Pro - remboursement 2nde quinzaine 07-2018', status=TransactionStatus.PENDING, idx=None, iban='FR7630007000111234567890144', bic='BDFEFR2LCCB'): payment = Payment() payment.booking = booking payment.amount = amount payment.author = author payment.iban = iban payment.bic = bic payment.recipientName = offerer.name payment.recipientSiren = offerer.siren payment_status = PaymentStatus() payment_status.status = status payment_status.date = datetime.utcnow() payment.statuses = [payment_status] payment.reimbursementRule = reimbursement_rule payment.reimbursementRate = reimbursement_rate if payment_message_name: payment.paymentMessage = create_payment_message(payment_message_name) elif payment_message: payment.paymentMessage = payment_message payment.transactionEndToEndId = transaction_end_to_end_id payment.transactionLabel = transaction_label payment.id = idx return payment
def menu_charge(request, request_id=0): if request.method == "POST": stripe.api_key = settings.STRIPE_API_KEY card = request.POST.get("stripeToken") m = [] food_request = get_request(request_id) payment = Payment() payment.amount = food_request.total payment.paidBy = request.user payment.description = "food delivery: " #+ item_list x = payment.amount * 100 #Convert from dolars to cents y = (x / 100) * 2.9 #Adjust stripe fees print card success, instance = payment.charge(int((x + y) + 30), card) if not success: raise forms.ValidationError("Error: %s" % instance.message) else: instance.amount = payment.amount instance.save() food_request.paid = True food_request.save() return HttpResponseRedirect("/") else: context = {'user': request.user, 'stripe_key': settings.STRIPE_PUB_KEY} return render(request, 'pay.html', context)
def CreatePayment(self,details): p = Payment() p.amount = details["amount"] p.company = details["company"] p.complete = False p.token = str(self.GenerateToken()) p.put() resp = { "success" : True , "token" : p.token } self.response.out.write(json.dumps(resp)) return True
def payments(id=None): if request.method == 'GET': if id is not None: payment = Payment.query.get( id) # None por defecto si no consigue el registro if payment: return jsonify(payment.serialize()), 200 return jsonify({"msg": "Financing Agreement not found"}), 404 else: payment = Payment.query.all() payment = list(map(lambda payment: payment.serialize(), payment)) return jsonify(payment), 200 if request.method == 'POST': urlPDF = request.json.get("urlPDF", None) amount = request.json.get("amount", None) bank = request.json.get("bank", None) payment_method = request.json.get("payment_method", None) rut = request.json.get("rut", None) if not urlPDF: return jsonify({"msg": "URL is required"}), 400 if not amount: return jsonify({"msg": "Amount is required"}), 400 if not bank: return jsonify({"msg": "Bank is required"}), 400 if not payment_method: return jsonify({"msg": "Payment Method is required"}), 400 if not rut: return jsonify({"msg": "RUT is required"}), 400 payment = Payment.query.filter_by(id=id).first() if payment: return jsonify({"msg": "Payment already exists"}), 400 payment = Payment() payment.urlPDF = urlPDF payment.amount = amount payment.bank = bank payment.payment_method = payment_method payment.rut = rut payment.save() return jsonify({"success": "Payment Register Successfully"}), 200
def make_payment(): try: amount = int(request.form.get('amount')) * 10 # toman to rial if amount < 10000: raise ValueError("حداقل مبلغ مجاز برای پرداخت ۱۰۰۰ تومان است.") phone_number = request.form.get('phone') if phone_number: if not phone_number.isnumeric(): raise ValueError("شماره تماس وارد شده نامعتبر است.") phone_number = f'0{int(phone_number)}' # convert to english digits if not re.match(r'^09\d{9}$', str(phone_number)): raise ValueError("شماره تماس وارد شده نامعتبر است.") # record payment data in database payment = Payment() payment.name = request.form.get('name') payment.email = request.form.get('email') payment.description = request.form.get('description') payment.amount = amount payment.phone_number = phone_number db.session.add(payment) db.session.commit() payment_url = webpay.payment( reference=payment.id, # unique ID amount_irr=amount, callback_url=url_for('verify_payment', _external=True), payer_mobile=phone_number) return redirect(payment_url) except ValueError as e: flash(str(e)) return redirect(url_for('donation_page')) except Exception: db.session.rollback() # ensure database session works after error traceback.print_exc() # print traceback and continue return redirect(url_for('donation_page'))
def test_generate_payment_csv_raw_contains_human_readable_status_with_details(self, app): # given payment = Payment() user = create_user(email='*****@*****.**') offerer = create_offerer() venue = create_venue(offerer) stock = create_stock_with_thing_offer(offerer=offerer, venue=venue, price=10) booking = create_booking(user, stock, venue=venue, token='ABCDEF', is_used=True) payment.booking = booking payment.booking.stock = stock payment_status = PaymentStatus() payment.transactionLabel = 'pass Culture Pro - remboursement 1ère quinzaine 07-2019' payment.amount = 50 payment_status.status = TransactionStatus.ERROR payment_status.detail = 'Iban non fourni' payment_status.date = datetime.utcnow() payment.statuses = [payment_status] # when raw_csv = ReimbursementDetails(payment).as_csv_row() # then assert raw_csv[13] == 'Erreur d\'envoi du remboursement : Iban non fourni'
def get(self, **kwargs): self.request.charset = 'utf-8' account = kwargs['account'] # Nos fijamos la ultima vez que lo pedimos, pedimos hasta hoy si estamos dentro de un mes max # Sino bajaremos en dos dias (probabilidad muy baja) upcfg = UPConfig.get_or_insert('main-config', last_ipn=datetime.now().date(), last_ipn_emi=datetime.now().date()) _from = upcfg.last_ipn if account == 'emi': _from = upcfg.last_ipn_emi _to = datetime.utcnow().date() if (_to - _from).days > 28: _to = _from + timedelta(days=28) # _to = date(2011,10,22) # _from = date(2011,9,24) # Bajamos el xml con la api de IPN _xml = ipn_download(account, _from, _to) dom = minidom.parseString(_xml) # self.response.write(_xml) # self.response.write(dom) # return # Verificamos que este todo bien el xml de vuelta state = int(get_xml_value(dom, 'State')) if state != 1: logging.error('Error al traer xml: %d [%s]' % (state, account)) self.response.write('error') return #logging.error('----------traje joya') # Parseamos y generamos los Payment to_save = [] for pay in dom.getElementsByTagName('Pay'): p = Payment() p.trx_id = str(pay.attributes['Trx_id'].value) # Rompemos la fecha (la esperamos en formato YYYYMMDD) tmp = get_xml_value(pay, 'Trx_Date') date_arr = tmp.split(' ')[0].split('-') p.date = date(int(date_arr[0]), int(date_arr[1]), int(date_arr[2])) # El monto lo ponemos en int por 10 p.amount = int(float(get_xml_value(pay, 'Trx_Payment')) * 10) p.tag_data = account p.assinged = 0 to_save.append(p) # Cuantos pagos recibimos? logging.info('Se recibieron %d pagos [%s]' % (len(to_save), account)) # Salvamos todos los payments juntos y la ultima vez que corrimos en una transaccion # def txn(): # if(len(to_save)): # db.put(to_save) # tmp = PaymentAssingMapper() # deferred.defer(tmp.run, _transactional=True) # taskqueue.add(url='/tsk/update_ipn/%s' % account, params={'date': _to.strftime('%Y%m%d'), 'account':account}, transactional=True) # db.run_in_transaction(txn) if (len(to_save)): db.put(to_save) tmp = PaymentAssingMapper() deferred.defer(tmp.run) taskqueue.add(url='/tsk/update_ipn/%s' % account, params={ 'date': _to.strftime('%Y%m%d'), 'account': account }) # Mandamos a correr la tarea de mapeo de pagos si bajamos alguno nuevo self.response.write('ok - end')