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

copy
@interface AMSVaultElement : AMSProductBase

Access singleton

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

@end

Name

Type

Description

shared

AMSVaultElement

AMSVaultElement singleton instance.

Instance methods

AMSVaultElement singleton instance provides the following methods:

Method name

Description

initConfiguration()

Used to initialize SDK configuration.

preload()

Used to preload WebApp pages and KYC page resources.

createComponent()

Used to create and display the card binding component UI.

reset()

Used to reset the card binding process and clear the current state.

onDestroy()

Used to destroy the instance and release all associated resources.

Property

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

Name

Type

Description

paymentDelegate

AMSPaymentProtocol?

Payment protocol delegate, refer to AMSPaymentProtocol

Usage instructions

Usage example

copy
#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