GithubHelp home page GithubHelp logo

absolutvodka8888 / payermodule Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 0.0 18 KB

Hỗ trợ làm màn hình thanh toán trên ứng dụng iOS/ iPad OS. Rate star nếu bạn thấy tốt, hoặc báo cáo cho tôi qua Issues

License: MIT License

Swift 100.00%

payermodule's Introduction

PayerModule

Hướng dẫn sử dụng module

Swift Package Manager: File -> Swift Package -> Add Package Dependency ...

dependencies: [
    .package(url: "https://github.com/absolutvodka8888/PayerModule.git", .upToNextMajor(from: "0.0.1"))
]

Import Module

import PayerModule

Cài đặt Module trong AppDelegate.swift :

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    Payer.shared.config(listSubscription: ["com.yourcompany.test.premium.weekly",
                                           "com.yourcompany.test.premium.monthly",
                                           "com.yourcompany.test.premium.yearly"],
                        appleSharedSecretKey: "you secret key")
    Payer.shared.completeTransactions { _, _ in}
    return true
}

Tải giá từ server về Vui lòng chạy trên máy thật và add sandbox tester

func getProductsInfo() {
    Payer.shared.getInfoSubscriptions { products in
        products.forEach { skProduct in
            if skProduct.productIdentifier == "com.yourcompany.premium.weekly" {
                let price = skProduct.localizedPrice ?? "Weekly $5.99 per week"
                self.btnWeekly.setTitle(price, for: .normal)
            }
            
            if skProduct.productIdentifier == "com.yourcompany.premium.monthly" {
                let price = skProduct.localizedPrice ?? "Monthly $9.99 per month"
                self.btnMonthly.setTitle(price, for: .normal)
            }
            
            if skProduct.productIdentifier == "com.yourcompany.premium.yearly" {
                let price = skProduct.localizedPrice ?? "Yearly $59.99 per year"
                self.btnYearly.setTitle(price, for: .normal)
            }
        }
    }
}

Thực thi lệnh mua hàng

func purchaseAProduct() {
    Payer.shared.purchase(product: "com.yourcompany.test.premium.weekly") { success, errorMsg in
        if success {
            //TODO: Thực hiện lệnh khi thanh toán thành công
            // ví dụ: ẩn màn hình IAP
        } else {
            //TODO: Hiển thị message lỗi thanh toán
            
        }
    }
}

func restore() {
    Payer.shared.restore { success, errorMsg in
        if success {
            //TODO: Thực hiện lệnh khi thanh toán thành công
            // ví dụ: ẩn màn hình IAP
        } else {
            //TODO: Hiển thị message lỗi thanh toán
        }
    }
}

Hàm hỗ trợ kiểm tra trạng thái IAP

let status = Payer.shared.isPurchased

payermodule's People

Contributors

absolutvodka8888 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.