import Foundation import RealmSwift import SSLCommerzSDK import UIKit class AddressPaymentViewModel: ObservableObject , SSLCommerzDelegate { //class AddressPaymentViewModel: ObservableObject{ var ssl: SSLCommerz? var totalAmount : Double = 0.0 var delivery_address : String = "" var name : String = "" var ph : String = "" init(total_amount : String , isCodeUsed : Bool , code : String) { self.totalAmount = Double(total_amount) ?? 0.0 self.CouponCode = code self.iCodeUsed = isCodeUsed getDeliveryAddress() } func createPayment() { let user = loadUser() let transID = currentTimeInMilliSeconds() ssl = SSLCommerz.init(integrationInformation: .init(storeID: STORE_ID, storePassword: STORE_PASS, totalAmount: totalAmount, currency: "BDT", transactionId: transID, productCategory: "product"), emiInformation: nil, customerInformation: .init(customerName: user?.firstName ?? "cus", customerEmail: user?.email ?? "cus", customerAddressOne: user?.billing.address1 ?? "cus", customerCity: user?.billing.city ?? "cus", customerPostCode: "111", customerCountry: "BD", customerPhone: user?.billing.phone ?? "cus"), shipmentInformation: nil, productInformation: nil, additionalInformation: nil) ssl?.delegate = self ssl?.start(in: (UIApplication.shared.windows.first?.rootViewController)!, shouldRunInTestMode: false) } func transactionCompleted(withTransactionData transactionData: TransactionDetails?){ CreateOrder(isPaid: true, method: "ssl") }