/wepay

Simple to integrate wechat pay and alipay.

Primary LanguageKotlinApache License 2.0Apache-2.0

WePay

English|中文

Features

  • Support wechat pay and alipay in one library.
  • Easy to listen pay status and result.
  • Easy to config and easy to use.

Getting started

The first step is to include WePay into your project, for example, as a Gradle compile dependency:

Because of using jitpack.io,so we need add the jitpack.io repository in your root project gradle:

allprojects {
 repositories {
    jcenter()
    //...some other repo.
    maven { url "https://jitpack.io" }
 }
}

and then add wepay dependency in your module gradle:

    implementation "com.github.wind0ws:wepay:1.0.0"

for gradle version below 3.0, just replace keyword implementation to compile

We are done for integration.

Now we write the hello world app.

First and foremost: You should apply appId,appSecret for alipay and wechat pay. You can apply it on there official website.

The flow of pay is :

  1. Create your order object.
  2. Create your pay config: AlipayConfig and WechatPayConfig.
  3. Let your activity or fragment implement PayStatusListener for listen pay status and result.
  4. Start PayEntryActivity for pay.

The full of demo is in this project app module.

  • Alipay

      PayEntryActivity.payStatusListener = this
      val payConfig = AliPayConfig(alipayAppId, rsaPrivateKey,false)
      val orderInfo = OrderInfo("admin",OrderUtils.createOutTradeNo(),123,"OrderTitle-admin-2017.10.11",
                  "Order detail", Date())
      PayEntryActivity.startAliPay(context,orderInfo,payConfig)
  • Wechat

    Attention please: because of wechat pay sdk restrict app pay entry activity name, so you should set this library PayEntryActivity alias to your manifest. such as:

            <activity-alias
              android:name=".wxapi.WXPayEntryActivity"
              android:exported="true"
              android:targetActivity="com.threshold.pay.PayEntryActivity"/>

    Now we write code for wechat pay.

      PayEntryActivity.payStatusListener = this
      val payConfig = WechatPayConfig("appid","appSecret","corpId","merchantId",
              "http://www.notifyUrl")
      val orderInfo = OrderInfo("admin", OrderUtils.createOutTradeNo(),123,"OrderTitle-admin-2017.10.11",
                  "Order detail", Date())
      PayEntryActivity.startWeChatPay(context,orderInfo,payConfig)

Proguard

See library proguard-rules.pro file.

LICENSE

Copyright (c) 2017-present, WePay Contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.