迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:serso/android-checkout开源软件地址:https://github.com/serso/android-checkout开源编程语言:Java 100.0%开源软件介绍:Checkout (Android In-App Billing Library)DescriptionCheckout is an implementation of Android In-App Billing API (v3+). Its main goal is to make integration of in-app products as simple and straightforward as possible: developers should not spend much time on implementing boring In-App Billing API but should focus on more important things - their apps. With this in mind, the library was designed to be fast, flexible and secure. Current version: 1.2.5 Why?Checkout solves common problems that developers face while working with billing on Android, such as:
Checkout can be used with any dependency injection framework or
without it. It has a clear distinction of a functionality available in
different contexts: purchase can be done only from Getting startedSetup
implementation 'org.solovyev.android:checkout:1.2.5' Note: if you get the following warning
you should change the dependencies of androidTestImplementation('com.android.support.test.espresso:espresso-core:x.y.z', {
// use version of jsr305 provided by Checkout
exclude group: 'com.google.code.findbugs', module: 'jsr305'
}) See Android Studio and Gradle documentation for details.
<dependency>
<groupId>org.solovyev.android</groupId>
<artifactId>checkout</artifactId>
<version>1.2.5</version>
<type>aar</type>
</dependency>
TutorialA tutorial for the sample app is available on Medium. Take a look if you prefer step-by-step guides over documentation. ExampleSay there is an app that contains one in-app product with "sku_01" id.
Then public class MyApplication extends Application {
private static MyApplication sInstance;
private final Billing mBilling = new Billing(this, new Billing.DefaultConfiguration() {
@Override
public String getPublicKey() {
return "Your public key, don't forget about encryption";
}
});
public MyApplication() {
sInstance = this;
}
public static MyApplication get() {
return sInstance;
}
public Billing getBilling() {
return mBilling;
}
} And public class MyActivity extends Activity implements View.OnClickListener {
private class PurchaseListener extends EmptyRequestListener<Purchase> {
@Override
public void onSuccess(Purchase purchase) {
// here you can process the loaded purchase
}
@Override
public void onError(int response, Exception e) {
// handle errors here
}
}
private class InventoryCallback implements Inventory.Callback {
@Override
public void onLoaded(Inventory.Products products) {
// your code here
}
}
private final ActivityCheckout mCheckout = Checkout.forActivity(this, MyApplication.get().getBilling());
private Inventory mInventory;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mCheckout.start();
mCheckout.createPurchaseFlow(new PurchaseListener());
mInventory = mCheckout.makeInventory();
mInventory.load(Inventory.Request.create()
.loadAllPurchases()
.loadSkus(ProductTypes.IN_APP, "sku_01"), new InventoryCallback());
}
@Override
protected void onDestroy() {
mCheckout.stop();
super.onDestroy();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mCheckout.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onClick(View v) {
mCheckout.whenReady(new Checkout.EmptyListener() {
@Override
public void onReady(BillingRequests requests) {
requests.purchase(ProductTypes.IN_APP, "sku_01", null, mCheckout.getPurchaseFlow());
}
});
}
} Advanced usageSamplesA sample app is available on Google Play (source code). There is also a tutorial for it on Medium. Building from the sourcesCheckout is built by Gradle. The project structure and build procedure are standard for Android libraries. An environmental variable ANDROID_HOME must be set before building and should point to Android SDK installation folder (f.e. /opt/android/sdk). Please refer to Gradle User Guide for more information about the building. Classes overviewCheckout contains three main classes: Billing, Checkout and Inventory. Billing is a core class of Checkout's implementation of the billing API. It is responsible for:
Only one instance of Billing should be used in the app in order to avoid multiple connections to the billing service. Though this class might be used directly it's easier to work with Checkout instead. Checkout is a middle tier of the library. It uses Billing in a
certain context, e.g. in Inventory loads information about products, SKUs and purchases. Its lifecycle is bound to the lifecycle of Checkout in which it was created. Purchase verificationBy default, Checkout uses simple purchase verification algorithm (see
DefaultPurchaseVerifier). As explained in Android documentation
it's better to verify purchases on a remote server. Checkout allows
you to provide your own PurchaseVerifier via ProguardLibrary's proguard rules are automatically added to the app project by Gradle. You can declare them explicitly by copying the contents of proguard-rules.txt to your proguard configuration. LicenseCopyright 2016 serso aka se.solovyev 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. ![]() |
2022-08-15
2022-08-17
2023-10-27
2022-09-23
2022-08-13
请发表评论