<commit_before>module RailsTrade::PaymentType::Alipay

  def alipay_prepay
    Alipay2::Service.trade_app_pay_params(subject: self.subject, out_trade_no: self.uuid, total_amount: self.amount.to_s)
  end

  def alipay_prepay_url(return_url: url_helpers.wait_my_order_url(self.id), notify_url: url_helpers.alipay_notify_payments_url)
    Alipay2::Service.trade_page_pay(
      { subject: subject, out_trade_no: uuid, total_amount: amount.to_s },
      { return_url: return_url, notify_url: notify_url }
    )
  end

  def alipay_result
    return self if self.payment_status == 'all_paid'

    result = Alipay2::Service.trade_query out_trade_no: self.uuid
    result = JSON.parse(result)
    result = result['alipay_trade_query_response']

    if result['trade_status'] == 'TRADE_SUCCESS'
      self.change_to_paid! type: 'AlipayPayment', payment_uuid: result['trade_no'], params: result
    else
      errors.add :base, result['msg']
      logger.error "Alipay: #{self.errors.full_messages.join(', ')}"<commit_msg>code style<commit_after>module RailsTrade::PaymentType::Alipay

  def alipay_prepay
    Alipay2::Service.trade_app_pay_params(
      subject: self.subject,
      out_trade_no: self.uuid,
      total_amount: self.amount.to_s
    )
  end

  def alipay_prepay_url(return_url: url_helpers.wait_my_order_url(self.id), notify_url: url_helpers.alipay_notify_payments_url)
    Alipay2::Service.trade_page_pay(
      { subject: subject, out_trade_no: uuid, total_amount: amount.to_s },
      { return_url: return_url, notify_url: notify_url }
    )
  end

  def alipay_result
    return self if self.payment_status == 'all_paid'

    result = Alipay2::Service.trade_query out_trade_no: self.uuid
    result = JSON.parse(result)
    result = result['alipay_trade_query_response']

    if result['trade_status'] == 'TRADE_SUCCESS'
      self.change_to_paid! type: 'AlipayPayment', payment_uuid: result['trade_no'], params: result
    else
      errors.add :base, result['msg']
      logger.error "Alipay: #{self.errors.full_messages.join(', ')}"
{'fraction_non_alphanumeric': 0.11040547142159257, 'fraction_numerical': 0.0029311187103077674, 'mean_word_length': 4.565217391304348, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4545802', 'n_tokens_mistral': 744, 'n_tokens_neox': 719, 'n_words': 122}