Skip to content

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

Notifications You must be signed in to change notification settings

absolutvodka8888/PayerModule

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages