package com.yidian.shenghuoquan.bxbirdbusiness.service

import com.yidian.bcommon.services.ZapServiceActionConstants
import com.yidian.shenghuoquan.bxbirdbusiness.ui.CommonWebViewActivity
import com.yidian.xarc.xrouter.ResultResolver
import com.yidian.yac.core.zap.ZapService
import org.json.JSONObject

/**
 * 支付服务
 */
class BPayService : ZapService() {

  private lateinit var resolver: ResultResolver

  override fun onAction(path: String, action: String, params: Any, options: Any, resolver: ResultResolver) {
    this.resolver = resolver
    params as JSONObject
    when (action) {
      ZapServiceActionConstants.ActionToPay -> transferPayment(params)
    }
  }

  override fun onExit() {
  }

  override fun onInit() {
  }

  /**
   * 调起支付
   */
  private fun transferPayment(params: JSONObject) {
    val payChannel = params.optString("payChannel")
    val charge = params.optString("data")
    // 进行调起支付，并返回支付结果
    CommonWebViewActivity.transferPayment(charge, resolver)
  }

}
