This commit is contained in:
2025-12-12 14:46:38 +08:00
parent 3813974eae
commit 1eeeef266b
8 changed files with 230 additions and 56 deletions

View File

@@ -45,8 +45,10 @@
[KBHUD showInfo:(sta == !KBBizCodeSuccess ? KBLocalized(@"Payment failed") : KBLocalized(@"Payment successful"))];
if (sta == KBBizCodeSuccess) {
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
[KBHUD showSuccess:@"Success"];
if (handler) handler(KBLocalized(@"Success"), nil);
} else {
[KBHUD showError:@"Failed"];
if (handler) handler(KBLocalized(@"Failed"), nil);
}
(void)weakSelf; // keep self during block life if needed

View File

@@ -0,0 +1,44 @@
//
// KBPayProductModel.h
// keyBoard
//
// Created to map /products/inApp/list responses to strongly typed objects.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/// 内购商品模型
@interface KBPayProductModel : NSObject
/// 主键 id
@property (nonatomic, assign) NSInteger identifier;
/// Apple IAP 商品编号
@property (nonatomic, copy, nullable) NSString *productId;
/// 商品类型(例如 in-app-purchase
@property (nonatomic, copy, nullable) NSString *type;
/// 商品名称(如 100、1000
@property (nonatomic, copy, nullable) NSString *name;
/// 单位(如 金币)
@property (nonatomic, copy, nullable) NSString *unit;
/// 有效期数值(可能为 0
@property (nonatomic, assign) NSInteger durationValue;
/// 有效期单位(如 day/week
@property (nonatomic, copy, nullable) NSString *durationUnit;
/// 有效期天数
@property (nonatomic, assign) NSInteger durationDays;
/// 价格
@property (nonatomic, assign) double price;
/// 货币符号
@property (nonatomic, copy, nullable) NSString *currency;
/// 文案描述
@property (nonatomic, copy, nullable) NSString *productDescription;
/// 展示金币(自动拼接单位)
- (NSString *)coinsDisplayText;
/// 展示价格,保留两位小数
- (NSString *)priceDisplayText;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,38 @@
//
// KBPayProductModel.m
// keyBoard
//
#import "KBPayProductModel.h"
#import <MJExtension/MJExtension.h>
@implementation KBPayProductModel
+ (NSDictionary *)mj_replacedKeyFromPropertyName {
return @{
@"identifier": @"id",
@"productDescription": @"description",
};
}
- (NSString *)coinsDisplayText {
NSString *name = self.name ?: @"";
NSString *unit = self.unit ?: @"";
if (name.length && unit.length) {
return [NSString stringWithFormat:@"%@ %@", name, unit];
}
if (name.length) { return name; }
if (unit.length) { return unit; }
return @"";
}
- (NSString *)priceDisplayText {
NSString *currency = self.currency ?: @"";
double priceValue = self.price;
if (currency.length > 0) {
return [NSString stringWithFormat:@"%@%.2f", currency, priceValue];
}
return [NSString stringWithFormat:@"%.2f", priceValue];
}
@end