Antom, leading provider of tailored payment solutions

AMSVaultElement

AMSVaultElement is the core class of Vaulting Element and is the main class used to integrate the Antom Vaulting Element independent card binding component in iOS applications. Merchants can complete SDK initialization configuration, create card binding components, submit card binding, reset, and destroy operations through this class.

Declaration

Objective-C

objectivec
@interface AMSVaultElement : AMSProductBase

Swift

swift
public class AMSVaultElement : AMSProductBase

Access singleton

Objective-C

objectivec
@property (class, nonatomic, readonly, strong) AMSVaultElement *shared;

@end

Swift

swift
public class var shared: AMSVaultElement { get }

Name
Type
Description
shared
AMSVaultElement
AMSVaultElement singleton instance.

Instance methods

AMSVaultElement singleton instance provides the following methods:
Method name
Description
Used to initialize SDK configuration.
Used to preload WebApp pages and KYC page resources.
Used to create and display the card binding component UI.
Used to reset the card binding process and clear the current state.
Used to destroy the instance and release all associated resources.

Property

Objective-C

objectivec
@property (nonatomic, weak, nullable) id<AMSVaultProtocol> paymentDelegate;

Swift
swift
public weak var paymentDelegate: AMSPaymentProtocol?
Name
Type
Description
paymentDelegate
AMSPaymentProtocol?
Payment protocol delegate, refer to AMSPaymentProtocol。

Usage instructions

Usage example

Objective-C
objectivec
#import <AMSFoundation/AMSFoundation-Swift.h>
#import <AMSElement/AMSElement-Swift.h>

@interface VaultViewController () <AMSPaymentProtocol>
@end

@implementation VaultViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // 1. Create configuration
    AMSVaultElementConfiguration *config = [AMSVaultElementConfiguration new];
    config.locale = @"en_US";
    config.options = @{
        @"sandbox": @YES,
        @"showLoading": @YES
    };

    // 2. Initialize SDK (with callback)
    [[AMSVaultElement shared] initConfiguration:config completion:^(AMSStatusResult * _Nonnull result) {
        if (result.status == AMSStatusResultTypeSUCCESS) {
            NSLog(@"Initialization successful");
        } else {
            NSLog(@"Initialization failed: %@", result.error.message);
        }
    }];

    // 3. Set delegate
    [AMSVaultElement shared].paymentDelegate = self;

    // 4. (Optional) Preload resources
    [[AMSVaultElement shared] preload];
}

- (void)startVaultingWithSessionData:(NSString *)sessionData {
    // 5. Create card binding component (with callback)
    [[AMSVaultElement shared] createComponent:sessionData completion:^(AMSStatusResult * _Nonnull result) {
        if (result.status == AMSStatusResultTypeSUCCESS) {
            NSLog(@"Component created successfully");
        }
    }];
}

- (void)submitVaulting {
    // 6. Submit card binding
    [[AMSVaultElement shared] submit:nil];
}

#pragma mark - AMSPaymentProtocol

- (void)onSubmitPayCallback:(AMSStatusResult * _Nullable)eventResult {
    switch (eventResult.status) {
        case AMSStatusResultTypeSUCCESS:
            NSLog(@"Binding successful");
            break;
        case AMSStatusResultTypeFAIL:
            NSLog(@"Binding failed: %@", eventResult.error.message);
            break;
        case AMSStatusResultTypePROCESSING:
            NSLog(@"Binding processing");
            break;
        case AMSStatusResultTypeCANCELLED:
            NSLog(@"Binding cancelled");
            break;
        default:
            break;
    }
}

- (void)onEventCallback:(NSString * _Nonnull)eventCode eventResult:(AMSEventResult * _Nonnull)eventResult {
    NSLog(@"Event callback: %@", eventCode);
}

- (void)dealloc {
    [[AMSVaultElement shared] onDestroy];
}

@end
Swift
swift
import AMSFoundation
import AMSElement

class VaultViewController: UIViewController, AMSPaymentProtocol {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 1. Create configuration
        let config = AMSVaultElementConfiguration()
        config.locale = "en_US"
        config.options = [
            "sandbox": true,
            "showLoading": true
        ]
        
        // 2. Initialize SDK
        AMSVaultElement.shared.initConfiguration(config) { result in
            if result.status == .SUCCESS {
                print("Initialization successful")
            } else {
                print("Initialization failed: \(result.error?.message ?? "")")
            }
        }
        
        // 3. Set delegate
        AMSVaultElement.shared.paymentDelegate = self
        
        // 4. (Optional) Preload resources
        AMSVaultElement.shared.preload()
    }
    
    func startVaulting(sessionData: String) {
        // 5. Create card binding component
        AMSVaultElement.shared.createComponent(sessionData) { result in
            if result.status == .SUCCESS {
                print("Component created successfully")
            }
        }
    }
    
    func onSubmitPayCallback(_ eventResult: AMSStatusResult?) {
        guard let result = eventResult else { return }
        switch result.status {
        case .SUCCESS:
            print("Binding successful")
        case .FAIL:
            print("Binding failed: \(result.error?.message ?? "")")
        case .PROCESSING:
            print("Binding processing")
        case .CANCELLED:
            print("Binding cancelled")
        default:
            break
        }
    }
    
    func onEventCallback(_ eventCode: String, eventResult: AMSEventResult) {
        print("Event callback: \(eventCode)")
    }
    
    // Destroy
    deinit {
        AMSVaultElement.shared.onDestroy()
    }
}