-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
981 additions
and
17 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.shu.alipay.data.api | ||
|
||
import com.shu.alipay.data.protocol.GetPaySignReq | ||
import com.shu.alipay.data.protocol.PayOrderReq | ||
import com.shu.base.data.protocol.BaseResp | ||
import retrofit2.http.Body | ||
import rx.Observable | ||
import retrofit2.http.POST | ||
|
||
|
||
/* | ||
支付 接口 | ||
*/ | ||
interface PayApi { | ||
|
||
/* | ||
获取支付宝支付签名 | ||
*/ | ||
@POST("pay/getPaySign") | ||
fun getPaySign(@Body req: GetPaySignReq): Observable<BaseResp<String>> | ||
|
||
/* | ||
刷新订单状态,已支付 | ||
*/ | ||
@POST("order/pay") | ||
fun payOrder(@Body req: PayOrderReq): Observable<BaseResp<String>> | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
AliPay/src/main/java/com/shu/alipay/data/protocol/GetPaySignReq.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.shu.alipay.data.protocol | ||
|
||
/* | ||
获取支付宝 支付签名 | ||
*/ | ||
data class GetPaySignReq(val orderId: Int, val totalPrice: Long) |
6 changes: 6 additions & 0 deletions
6
AliPay/src/main/java/com/shu/alipay/data/protocol/PayOrderReq.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.shu.alipay.data.protocol | ||
|
||
/* | ||
支付订单 | ||
*/ | ||
data class PayOrderReq(val orderId:Int) |
34 changes: 34 additions & 0 deletions
34
AliPay/src/main/java/com/shu/alipay/data/repository/PayRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.shu.alipay.data.repository | ||
|
||
|
||
import com.shu.alipay.data.api.PayApi | ||
import com.shu.alipay.data.protocol.GetPaySignReq | ||
import com.shu.alipay.data.protocol.PayOrderReq | ||
import com.shu.base.data.net.RetrofitFactory | ||
import com.shu.base.data.protocol.BaseResp | ||
import javax.inject.Inject | ||
|
||
import rx.Observable | ||
|
||
|
||
/* | ||
支付数据层 | ||
*/ | ||
class PayRepository @Inject constructor() { | ||
|
||
/* | ||
获取支付宝支付签名 | ||
*/ | ||
fun getPaySign(orderId: Int, totalPrice: Long): Observable<BaseResp<String>> { | ||
return RetrofitFactory.instance.create(PayApi::class.java).getPaySign(GetPaySignReq(orderId, totalPrice)) | ||
} | ||
|
||
/* | ||
刷新订单状态已支付 | ||
*/ | ||
fun payOrder(orderId: Int): Observable<BaseResp<String>> { | ||
return RetrofitFactory.instance.create(PayApi::class.java).payOrder(PayOrderReq(orderId)) | ||
} | ||
|
||
|
||
} |
16 changes: 16 additions & 0 deletions
16
AliPay/src/main/java/com/shu/alipay/injection/component/PayComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.shu.alipay.injection.component | ||
|
||
import com.shu.alipay.injection.module.PayModule | ||
import com.shu.alipay.ui.activity.CashRegisterActivity | ||
import com.shu.base.injection.PerComponentScope | ||
import com.shu.base.injection.component.ActivityComponent | ||
import dagger.Component | ||
|
||
/* | ||
支付Component | ||
*/ | ||
@PerComponentScope | ||
@Component(dependencies = arrayOf(ActivityComponent::class),modules = arrayOf(PayModule::class)) | ||
interface PayComponent { | ||
fun inject(activity: CashRegisterActivity) | ||
} |
19 changes: 19 additions & 0 deletions
19
AliPay/src/main/java/com/shu/alipay/injection/module/PayModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.shu.alipay.injection.module | ||
|
||
import com.shu.alipay.service.PayService | ||
import com.shu.alipay.service.impl.PayServiceImpl | ||
import dagger.Module | ||
import dagger.Provides | ||
|
||
/* | ||
支付 Module | ||
*/ | ||
@Module | ||
class PayModule { | ||
|
||
@Provides | ||
fun providePayService(payService: PayServiceImpl): PayService { | ||
return payService | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
AliPay/src/main/java/com/shu/alipay/presenter/PayPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.shu.alipay.presenter | ||
|
||
import com.shu.alipay.presenter.view.PayView | ||
import com.shu.alipay.service.PayService | ||
import com.shu.base.ext.excute | ||
import com.shu.base.presenter.BasePresenter | ||
import com.shu.base.rx.BaseSubscriber | ||
import javax.inject.Inject | ||
|
||
/* | ||
支付Presenter | ||
*/ | ||
class PayPresenter @Inject constructor() : BasePresenter<PayView>() { | ||
@Inject | ||
lateinit var service: PayService | ||
|
||
/* | ||
获取支付签名 | ||
*/ | ||
fun getPaySign(orderId: Int, totalPrice: Long) { | ||
if (!checkNetWork()) { | ||
return | ||
} | ||
mView.showLoading() | ||
service.getPaySign(orderId,totalPrice).excute(object : BaseSubscriber<String>(mView) { | ||
override fun onNext(t: String) { | ||
mView.onGetSignResult(t) | ||
} | ||
}, lifecycleProvider) | ||
|
||
} | ||
|
||
/* | ||
订单支付,同步订单状态 | ||
*/ | ||
fun payOrder(orderId: Int) { | ||
if (!checkNetWork()) { | ||
return | ||
} | ||
mView.showLoading() | ||
service.payOrder(orderId).excute(object : BaseSubscriber<Boolean>(mView) { | ||
override fun onNext(t: Boolean) { | ||
mView.onPayOrderResult(t) | ||
} | ||
}, lifecycleProvider) | ||
|
||
} | ||
|
||
|
||
|
||
} |
16 changes: 16 additions & 0 deletions
16
AliPay/src/main/java/com/shu/alipay/presenter/view/PayView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.shu.alipay.presenter.view | ||
|
||
import com.shu.base.presenter.view.BaseView | ||
|
||
|
||
/* | ||
支付 视图回调 | ||
*/ | ||
interface PayView : BaseView { | ||
|
||
//获取支付签名 | ||
fun onGetSignResult(result: String) | ||
//同步支付成功状态 | ||
fun onPayOrderResult(result: Boolean) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.shu.alipay.service | ||
|
||
import rx.Observable | ||
|
||
/* | ||
支付 业务接口 | ||
*/ | ||
interface PayService { | ||
|
||
/* | ||
获取支付宝支付签名 | ||
*/ | ||
fun getPaySign(orderId: Int, totalPrice: Long): Observable<String> | ||
|
||
/* | ||
刷新订单状态已支付 | ||
*/ | ||
fun payOrder(orderId: Int): Observable<Boolean> | ||
} |
31 changes: 31 additions & 0 deletions
31
AliPay/src/main/java/com/shu/alipay/service/impl/PayServiceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.shu.alipay.service.impl | ||
|
||
import com.shu.alipay.data.repository.PayRepository | ||
import com.shu.alipay.service.PayService | ||
import com.shu.base.ext.convert | ||
import com.shu.base.ext.convertBoolean | ||
import rx.Observable | ||
import javax.inject.Inject | ||
|
||
/* | ||
支付 业务实现类 | ||
*/ | ||
class PayServiceImpl @Inject constructor(): PayService { | ||
|
||
@Inject | ||
lateinit var repository: PayRepository | ||
|
||
/* | ||
获取支付签名 | ||
*/ | ||
override fun getPaySign(orderId: Int, totalPrice: Long): Observable<String> { | ||
return repository.getPaySign(orderId,totalPrice).convert() | ||
} | ||
|
||
/* | ||
支付订单,同步订单状态 | ||
*/ | ||
override fun payOrder(orderId: Int): Observable<Boolean> { | ||
return repository.payOrder(orderId).convertBoolean() | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
AliPay/src/main/java/com/shu/alipay/ui/activity/CashRegisterActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package com.shu.alipay.ui.activity | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import com.alibaba.android.arouter.facade.annotation.Autowired | ||
import com.alibaba.android.arouter.facade.annotation.Route | ||
import com.alibaba.android.arouter.launcher.ARouter | ||
import com.alipay.sdk.app.EnvUtils | ||
import com.alipay.sdk.app.PayTask | ||
import com.shu.alipay.injection.component.DaggerPayComponent | ||
import com.shu.alipay.injection.module.PayModule | ||
import com.shu.alipay.presenter.PayPresenter | ||
import com.shu.alipay.presenter.view.PayView | ||
import com.shu.base.ext.onClick | ||
import com.shu.base.ui.activity.BaseMvpActivity | ||
import com.shu.base.utils.YuanFenConverter | ||
import com.shu.order.R | ||
import com.shu.provider.common.ProviderConstant | ||
import com.shu.provider.router.RouterPath | ||
import kotlinx.android.synthetic.main.activity_cash_register.* | ||
import org.jetbrains.anko.doAsync | ||
import org.jetbrains.anko.toast | ||
import org.jetbrains.anko.uiThread | ||
|
||
/* | ||
收银台界面 | ||
*/ | ||
@Route(path = RouterPath.PaySDK.PATH_PAY) | ||
class CashRegisterActivity: BaseMvpActivity<PayPresenter>(), PayView,View.OnClickListener { | ||
/* | ||
Dagger注册 | ||
*/ | ||
override fun injectComponent() { | ||
DaggerPayComponent.builder().activityComponent(activityComponent).payModule(PayModule()).build().inject(this) | ||
mPresenter.mView = this | ||
} | ||
|
||
//订单号 | ||
var mOrderId:Int = 0 | ||
//订单总价格 | ||
var mTotalPrice:Long = 0 | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_cash_register) | ||
|
||
EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX) | ||
|
||
ARouter.getInstance().inject(this) | ||
|
||
initView() | ||
initData() | ||
} | ||
|
||
/* | ||
初始化数据 | ||
*/ | ||
private fun initData() { | ||
mOrderId = intent.getIntExtra(ProviderConstant.KEY_ORDER_ID,-1) | ||
mTotalPrice = intent.getLongExtra(ProviderConstant.KEY_ORDER_PRICE,-1) | ||
|
||
mTotalPriceTv.text = YuanFenConverter.changeF2YWithUnit(mTotalPrice) | ||
} | ||
|
||
/* | ||
初始化视图 | ||
*/ | ||
private fun initView() { | ||
mAlipayTypeTv.isSelected = true | ||
mAlipayTypeTv.onClick(this) | ||
mWeixinTypeTv.onClick(this) | ||
mBankCardTypeTv.onClick(this) | ||
mPayBtn.onClick(this) | ||
} | ||
|
||
/* | ||
获取支付签名回调 | ||
*/ | ||
override fun onGetSignResult(result: String) { | ||
doAsync { | ||
val resultMap:Map<String,String> = PayTask(this@CashRegisterActivity).payV2(result,true) | ||
uiThread { | ||
if (resultMap["resultStatus"].equals("9000")){ | ||
mPresenter.payOrder(mOrderId) | ||
}else{ | ||
toast("支付失败${resultMap["memo"]}") | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
/* | ||
支付订单回调 | ||
*/ | ||
override fun onPayOrderResult(result: Boolean) { | ||
toast("支付成功") | ||
finish() | ||
} | ||
|
||
/* | ||
点击事件 | ||
*/ | ||
override fun onClick(v: View) { | ||
when(v.id){ | ||
R.id.mAlipayTypeTv -> {updatePayType(true,false,false)} | ||
R.id.mWeixinTypeTv -> {updatePayType(false,true,false)} | ||
R.id.mBankCardTypeTv -> {updatePayType(false,false,true)} | ||
R.id.mPayBtn -> { | ||
mPresenter.getPaySign(mOrderId,mTotalPrice) | ||
} | ||
} | ||
} | ||
|
||
/* | ||
选择支付类型,UI变化 | ||
*/ | ||
private fun updatePayType(isAliPay:Boolean,isWeixinPay:Boolean,isBankCardPay:Boolean){ | ||
mAlipayTypeTv.isSelected = isAliPay | ||
mWeixinTypeTv.isSelected = isWeixinPay | ||
mBankCardTypeTv.isSelected = isBankCardPay | ||
} | ||
} |
Oops, something went wrong.