def pretranslatedMyDownloadedList(self): """ 내가 구매한 다운로드 목록 리스트 **Parameters** #. **"page"**: 페이지 (OPTIONAL) **Response** #. **200** .. code-block:: json :linenos: { "data": [ { "id": 3, "resource_id": 4, "is_paid": false, "is_sent": false, "is_downloaded": false, "feedback_score": null, "request_timestamp": "Sun, 12 Feb 2017 19:40:45 GMT" } ] } """ pretranslatedObj = Pretranslated(g.db) user_id = ciceron_lib.get_user_id(g.db, session['useremail']) result = pretranslatedObj.getMyDownloadList(user_id) return make_response(json.jsonify(data=result), 200)
def postProcess2(self, user_email=None, product=None, request_id=None, payment_platform=None, is_succeeded=None, amount=0, point_for_use=0, promo_type=None, promo_code=None, paymentId=None, PayerID=None, ciceron_order_id=None): user_id = ciceron_lib.get_user_id(self.conn, user_email) if is_succeeded == False: return False, None # Point deduction if use_point > 0: self._pointDeduction(user_id, use_point) # Use promo code if promo_type == 'common': self.commonPromotionCodeExecutor(user_email, promo_code) elif promo_type == 'indiv': self.individualPromotionCodeExecutor(user_email, promo_code) # Check payment in each payment platform payment_id = "" if payment_platform == 'paypal' and is_succeeded == True: payment_id = paymentId payer_id = PayerID self._paypalPaymentCheck(payment_id, payer_id) elif payment_platform == 'alipay' and is_succeeded == True: payment_id = ciceron_order_id elif payment_platform == 'iamport' and is_succeeded == True: payment_id = ciceron_order_id elif payment_platform == 'point' and is_succeeded == True: payment_id = ciceron_order_id markAsPaid_api = self._organizePostprocessApiAddress( product, request_id) self._insertPaymentInfo(product, request_id, user_id, payment_platform, payment_id, amount) return True, markAsPaid_api
def _pointDeduction(self, user_email, point_for_use): cursor = self.conn.cursor() user_id = ciceron_lib.get_user_id(self.conn, user_email) if point_for_use > 0: cursor.execute( """ UPDATE CICERON.return_point SET amount = amount - %s WHERE id = %s """, ( point_for_use, user_id, ))
def individualPromotionCodeExecutor(self, user_email, code): """ 개인용 프로모션 코드 적용기이다. """ cursor = self.conn.cursor() user_id = ciceron_lib.get_user_id(self.conn, user_email) query_commonPromotionCodeExeutor = """ UPDATE CICERON.PROMOTIONCODES_USER SET is_used = true WHERE user_id = %s AND text = UPPER(%s) """ cursor.execute(query_commonPromotionCodeExeutor, ( user_id, code.upper(), ))
def addUserAsDownloader(self, resource_id, email): cursor = self.conn.cursor() query_checkCount = """ SELECT count(*) FROM CICERON.F_PRETRANSLATED_DOWNLOADED_USER WHERE resource_id = %s AND email = %s """ cursor.execute(query_checkCount, ( resource_id, email, )) cnt = cursor.fetchone()[0] if cnt > 0: # 같은 유저가 같은 번역물 다운로드 권한을 # 여러번 Call하는 상황을 막아야 한다. return 2 query_addUser = """ INSERT INTO CICERON.F_PRETRANSLATED_DOWNLOADED_USER (id, resource_id, is_user, email, is_paid, is_sent, is_downloaded, request_timestamp) VALUES (%s, %s, %s, %s, false, false, false, CURRENT_TIMESTAMP) """ user_id = ciceron_lib.get_user_id(self.conn, email) is_user = False if user_id == -1 else True new_downloader_id = ciceron_lib.get_new_id( self.conn, "F_PRETRANSLATED_DOWNLOADED_USER") try: cursor.execute(query_addUser, ( new_downloader_id, resource_id, is_user, email, )) except Exception: traceback.print_exc() self.conn.rollback() return 1 return 0
def commonPromotionCodeExecutor(self, user_email, code): """ 프로모션 코드를 적용한다. """ cursor = self.conn.cursor() user_id = ciceron_lib.get_user_id(self.conn, user_email) query_searchPromoCodeId = """ SELECT id FROM CICERON.PROMOTIONCODES_COMMON WHERE text = UPPER(%s) """ cursor.execute(query_searchPromoCodeId, (code.upper(), )) ret = cursor.fetchone() if ret is None or len(ret) == 0: raise Exception("Promo code '%s' doesn't exist!" % code) code_id = ret[0] query_commonPromotionCodeExeutor = """ INSERT INTO CICERON.USEDPROMOTION_COMMON VALUES (%s,%s) """ cursor.execute(query_commonPromotionCodeExeutor, ( code_id, user_id, ))
def postProcess(self, user_email=None, request_id=None, pay_via=None, pay_by=None, is_succeeded=None, amount=0, use_point=0, promo_type=None, promo_code=None, is_additional=None, is_groupRequest=None, is_public=None, paymentId=None, PayerID=None, ciceron_order_id=None): user_id = ciceron_lib.get_user_id(self.conn, user_email) if is_succeeded == False: return False # Point deduction if use_point > 0: self._pointDeduction(user_id, use_point) # Use promo code if promo_type == 'common': self.commonPromotionCodeExecutor(user_email, promo_code) elif promo_type == 'indiv': self.individualPromotionCodeExecutor(user_email, promo_code) # Check payment in each payment platform payment_id = "" if pay_via == 'paypal' and is_succeeded == True: payment_id = paymentId payer_id = PayerID self._paypalPaymentCheck(payment_id, payer_id) elif pay_via == 'alipay' and is_succeeded == True: payment_id = ciceron_order_id elif pay_via == 'iamport' and is_succeeded == True: payment_id = ciceron_order_id elif pay_via == 'point' and is_succeeded == True: payment_id = ciceron_order_id # Set to 'paid' self._markAsPaid(request_id, is_additional) # Group request processing if is_groupRequest == 'true': groupRequestObj = GroupRequest(self.conn) groupRequestObj.updatePaymentInfo(request_id, user_id, pay_via, payment_id) if is_public == 'true': requestResellObj = RequestResell(self.conn) requestResellObj.setToPaid(request_id, user_id, pay_via, payment_id) # Insert payment info self._insertPaymentInfo(request_id, user_id, pay_via, payment_id, amount) return True
def payment(self): """ 결제 진행 API **Parameters** #. **"payment_platform"**: 지불 플랫폼 ("alipay", "paypal", "iamport", "point") #. **"product"**: 구매한 내부 플랫폼 이름 ("l10n", "pretranslation", "groupRequest", "f2finterpreter") #. **"request_id"**: 각 플랫폼에서의 의뢰 번호 #. **"amount"**: 지불 금액 (단위: USD) #. **"promo_type"**: 쿠폰 타입 ("indiv": 개인적용, "common": 마구 뿌린 프로모션) #. **"point_for_use"**: 결제시 사용할 포인트. 사용한 만큼 결제금에서 차감 #. **"card_number"**: 카드번호 (iamport에서만 필요,"xxxx-xxxx-xxxx-xxxx" or "xxxx-xxxx-xxxx-xxx"[AMEX] ) #. **"expiry"**: 유효기간 (iamport에서만 필요, "YYYY-MM") #. **"birth"**: [개인] 생년월일 "YYMMDD", [사업자] 사업자등록번호 "xxxxxxxxxx" (iamport 전용) #. **"pwd_2digit"**: 비밀번호 앞 2자리 (iamport 전용) #. **"buyer_name"**: 구매자 이름 (iamport 전용, OPTIONAL) #. **"buyer_email"**: 구매자 이메일 (iamport 전용, OPTIONAL) **Response** **200** .. code-block:: json :linenos: { "link": "http://payment.paypalalipay.com/paymemnt/blahblah" // 리다이렉팅 할 주소 } **410**: 포인트 보유량이 사용할 포인트보다 적음 **411**: 유효하지 않은 쿠폰 번호 **412**: 결제준비 실패 """ paymentObj = Payment(g.db) parameters = parse_request(request) email = session['useremail'] payment_platform = parameters['payment_platform'] product = float(parameters['product']) request_id = float(parameters['request_id']) amount = float(parameters['amount']) promo_type = parameters.get('promo_type', 'null') promo_code = parameters.get('promo_code', 'null') point_for_use = float(parameters.get('point_for_use', 0)) user_id = ciceron_lib.get_user_id(g.db, email) # 아임포트 직접결제를 위한 파라미터 payload = None if payment_platform == 'iamport': payload = {} payload['card_number'] = parameters['card_number'] payload['expiry'] = parameters['expiry'] payload['birth'] = parameters['birth'] payload['pwd_2digit'] = parameters['pwd_2digit'] payload['buyer_name'] = parameters.get('buyer_name', "Anonymous") payload['buyer_email'] = parameters.get('buyer_email', "*****@*****.**") # 결제금액 없으면 바로 지불처리 if amount < 0.01: is_payment_ok, link = paymentObj.pointPayment2( is_prod, request_id, email, 0, product) if is_payment_ok == True: return make_response(json.jsonify(link=link), 200) else: return make_response(json.jsonify(link=link), 412) is_prod = False if os.environ.get('PURPOSE') == 'PROD': is_prod = True # Point test cur_amount = amount if point_for_use > 0.00001: is_point_usable, cur_amount = paymentObj.checkPoint( user_id, point_for_use) if cur_amount - point_for_use < -0.00001: return make_response(json.jsonify(message="Fail"), 410) # Promo code test if promo_type != 'null': isCommonCode, commonPoint, commonMessage = paymentObj.commonPromotionCodeChecker( email, promo_code) isIndivCode, indivPoint, indivMessage = paymentObj.individualPromotionCodeChecker( email, promo_code) if isCommonCode == 0: cur_amount = cur_amount - commonPoint elif isIndivCode == 0: cur_amount = cur_amount - indivPoint else: return make_response(json.jsonify(message="Fail"), 411) # Send payment request is_payment_ok, link = False, "" if payment_platform == 'alipay' and cur_amount > 0.0001: is_payment_ok, link = paymentObj.alipayPayment2( is_prod, request_id, email, cur_amount, product, point_for_use=point_for_use, promo_type=promo_type, promo_code=promo_code) elif payment_platform == 'paypal' and cur_amount > 0.0001: is_payment_ok, link = paymentObj.paypalPayment2( is_prod, request_id, email, cur_amount, product, point_for_use=point_for_use, promo_type=promo_type, promo_code=promo_code) elif payment_platform == 'iamport' and cur_amount > 0.0001: is_payment_ok, link = paymentObj.iamportPayment2( is_prod, request_id, email, cur_amount, product, point_for_use=point_for_use, promo_type=promo_type, promo_code=promo_code, **payload) else: is_payment_ok, link = paymentObj.pointPayment2( is_prod, request_id, email, cur_amount, product, point_for_use=point_for_use, promo_type=promo_type, promo_code=promo_code) # Return if is_payment_ok: g.db.commit() return make_response(json.jsonify(link=link), 200) else: g.db.rollback() return make_response(json.jsonify(message="Fail"), 412)