def _callback(self, request, *args, **kwargs): start_time = int(time.time() * 1000) payment = Payment(request) payment_id = request.REQUEST.get('paymentId', None) payment_info = PaymentInfo.get_by_point_code(payment_id) self.write_log_debug(u'_callback: payment_id = %s', payment_id) self.write_log_debug(u'_callback: payment_info = %s', payment_info) if payment.is_success(): self.write_log_debug(u'_callback: payment is success') gacha_kwargs = self.get_gacha_kwargs(request, *args, **kwargs) try: with self.transaction_context(self.player, **gacha_kwargs): if not self.check(request, *args, **kwargs): raise self._CheckError # Kombu が AMQP tx に未対応であるため, # Timeout か DeadLock が発生すると # Background ではメッセージが飛んでしまう. # よって, 暫くここはコメントアウトしとく. #self.write_log_debug(u'_callback: start gacha method') #self.gacha(request, *args, **kwargs) #self.write_log_debug(u'_callback: end gacha method') end_time = int(time.time() * 1000) if end_time - start_time > 4000: raise self._TimeoutError # Kombu が AMQP tx を使えないため, # 苦肉の策で, gacha() を transaction の外に出す. # Foregrand は諦める. with self.transaction_context(self.player, **gacha_kwargs): self.write_log_debug(u'_callback: start gacha method') self.gacha(request, *args, **kwargs) self.write_log_debug(u'_callback: end gacha method') except self._CheckError: self.write_log_debug(u'_callback: check is False') self.kvs.set('session_result', {'status': 'disable'}) except self._TimeoutError: self.write_log_error(u'_callback: TimeoutError %sms', end_time - start_time) self.kvs.set('session_result', {'status': 'error'}) except: traceback.print_exception(file=sys.stdout, *sys.exc_info()) self.write_log_except() self.kvs.set('session_result', {'status': 'error'}) else: payment_info.save_as_succeeded() self.write_log_debug(u'_callback: return OK') return HttpResponse('OK', mimetype='text/plain') else: self.write_log_debug(u'_callback: payment is cancel') self.kvs.set('session_result', {'status': 'cancel'}) payment_info.save_as_canceled() self.write_log_debug(u'_callback: return NG') return HttpResponseBadRequest('NG', mimetype='text/plain')
def finish(self): """ finish処理 返り値: True: 購入 False : キャンセル finish processing return value: True: bought False: cancel """ point_code = self.request.REQUEST.get('paymentId', None) if point_code is not None: payment_obj = PaymentInfo.get_by_point_code(point_code) return payment_obj.is_succeeded()
def callback(self): """ PaymentCallback処理 :return: True: 購入成功 False: 購入キャンセル PaymentCallback processing :return: True: success of payment processing False: payment has been canceled """ Log.debug("callback-------------") point_code = self.request.REQUEST.get('paymentId', None) payment_obj = PaymentInfo.get_by_point_code(point_code) res = self.is_success() if res: payment_obj.save_as_succeeded() else: payment_obj.save_as_canceled() Log.debug("callback-------------") return res