# AMSPaymentProtocol

> Callback protocol for payment or card vaulting processes. This protocol defines callback methods for payment and card vaulting lifecycle events.

Callback protocol for payment or card vaultibindingng processes. This protocol defines callback methods for payment and card binding lifecycle events. All methods are optional. To receive these callbacks, set the _paymentDelegate_ property on [`AMSPaymentElement.shared`](https://docs.antom.com/ac/sdks/ios_AMSPaymentElement.md).

## Declaration

#### Tab: Objective-C

```objectivec
@protocol AMSPaymentProtocol <NSObject>

@optional

- (void)onLaunch;
- (void)onReady;
- (void)onEventCallback:(NSString * _Nonnull)eventCode
            eventResult:(AMSEventResult * _Nonnull)eventResult;
- (void)onSizeChanged:(CGFloat)width
               height:(CGFloat)height;
- (void)onBeforeSubmit:(NSDictionary * _Nullable)paymentInfo
            completion:(void (^)(AMSResultInfo * _Nonnull))completion;
- (void)onSubmitPayCallback:(AMSStatusResult * _Nullable)eventResult;

@end
```

#### Tab: Swift

```swift
public protocol AMSPaymentProtocol : NSObjectProtocol {
    optional func onLaunch()
    optional func onReady()
    optional func onEventCallback(_ eventCode: String, eventResult: AMSEventResult)
    optional func onSizeChanged(_ width: CGFloat, height: CGFloat)
    optional func onBeforeSubmit(_ paymentInfo: [AnyHashable: Any]?, completion: @escaping (AMSResultInfo) -> Void)
    optional func onSubmitPayCallback(_ eventResult: AMSStatusResult?)
}
```

## Callback methods

### onLaunch()

Called when SDK initialization is completed.

#### Tab: Objective-C

```objectivec
- (void)onLaunch;
```

#### Tab: Swift

```swift
optional func onLaunch()
```

### onReady()

Called when list data rendering is completed and buyers can start interacting.

#### Tab: Objective-C

```objectivec
- (void)onReady;
```

#### Tab: Swift

```swift
optional func onReady()
```

### onEventCallback()

Called when internal SDK events occur.

#### Tab: Objective-C

```objectivec
- (void)onEventCallback:(NSString * _Nonnull)eventCode
            eventResult:(AMSEventResult * _Nonnull)eventResult;
```

#### Tab: Swift

```swift
optional func onEventCallback(_ eventCode: String, eventResult: AMSEventResult)
```

| **Parameter** | **Type** | **Required** | **Description** |
| --- | --- | --- | --- |
| _eventCode_ | String | Yes | Event code, identifying the event type. |
| _eventResult_ | [AMSEventResult](https://docs.antom.com/ac/sdks/ios_AMSEventResult.md) | Yes | Event result. |

### onSizeChanged()

Called when component size changes.

#### Tab: Objective-C

```objectivec
- (void)onSizeChanged:(CGFloat)width
               height:(CGFloat)height;
```

#### Tab: Swift

```swift
optional func onSizeChanged(_ width: CGFloat, height: CGFloat)
```

| **Parameter** | **Type** | **Required** | **Description** |
| --- | --- | --- | --- |
| _width_ | CGFloat | Yes | Component‘s new width. |
| _height_ | CGFloat | Yes | Component‘s new height. |

### onBeforeSubmit()

Custom processing callback before payment submission or card binding. Merchants can modify payment parameters or decide whether to continue submission in this callback.

#### Tab: Objective-C

```objectivec
- (void)onBeforeSubmit:(NSDictionary * _Nullable)paymentInfo
            completion:(void (^)(AMSResultInfo * _Nonnull))completion;
```

#### Tab: Swift

```swift
optional func onBeforeSubmit(_ paymentInfo: [AnyHashable: Any]?, completion: @escaping (AMSResultInfo) -> Void)
```

| **Parameter** | **Type** | **Required** | **Description** |
| --- | --- | --- | --- |
| _paymentInfo_ | \[AnyHashable: Any\]? | Yes | Payment or card binding information to be processed. |
| _completion_ | ([AMSResultInfo](https://docs.antom.com/ac/sdks/ios_AMSResultInfo.md)) -> Void | Yes | Control the payment or card binding process through [`AMSResultInfo`](https://docs.antom.com/ac/sdks/ios_AMSResultInfo.md) (action, scene, data). |

### onSubmitPayCallback()

Result callback after submitting payment or card binding.

#### Tab: Objective-C

```objectivec
- (void)onSubmitPayCallback:(AMSStatusResult * _Nullable)eventResult;
```

#### Tab: Swift

```swift
optional func onSubmitPayCallback(_ eventResult: AMSStatusResult?)
```

| **Parameter** | **Type** | **Required** | **Description** |
| --- | --- | --- | --- |
| _eventResult_ | [AMSStatusResult?](https://docs.antom.com/ac/sdks/ios_AMSStatusResult.md) | Yes | Submission result, including status code or error information. |