// // ASPaypalManager.m // Asteria // // Created by xingyu on 2024/5/14. // #import "ASPaypalManager.h" @implementation ASPaypalManager static ASPaypalManager *_instance = nil; + (instancetype)sharedInstance { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _instance = [[ASPaypalManager alloc] init]; }); return _instance; } - (void)checkoutPayWithMethodType:(NSString *)payType completion:(void (^ __nullable)(NSUInteger isSucess , id payData))completion { UIViewController *topVC = topViewController(); if ([payType isEqualToString:@"paypal_express"]) {//paypal K_WEAK_SELF; [ASNetTools.shared getWithPath:Chectout_Pay_Paypal_Url param:@{} success:^(id _Nonnull json) { K_STRONG_SELF; NSDictionary *dataDic = (NSDictionary *)json; NSString *urlStr = AS_String_NotNull(dataDic[@"url"]); dispatch_async(dispatch_get_main_queue(), ^{ [self tool_gotoWebPay:urlStr withVC:topVC completion:completion]; }); NSLog(@"=====%@", json); } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { }]; } else if ([payType isEqualToString:@"stripe_payments"]) {//visa } else if ([payType isEqualToString:@"afterpay_payment"]) {//afterpay } else if ([payType isEqualToString:@"klarna_kco"]) {//klarna } else { } } - (void)tool_gotoWebPay:(NSString *)urlStr withVC:(UIViewController *)tmpvc completion:(void (^ __nullable)(NSUInteger isSucess , id payData))completion{ XXX_BaseWebC *vc = [[XXX_BaseWebC alloc] init]; vc.isPayType = YES; vc.WebViewBlock = ^(NSUInteger status, id _Nonnull webData) { if(status == 1){ if(completion){ completion(1, webData); } }else{ if(completion){ completion(0, webData); } } }; [vc xxx_dsWebLoadUrl:urlStr]; vc.modalPresentationStyle = UIModalPresentationFullScreen; [tmpvc presentViewController:vc animated:YES completion:nil]; } @end