# iOS

{% tabs %}
{% tab title="Prebuilt checkout page" %}
![Mobile Sdk initiate transaction schematic diagram](https://3906929740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQyT5pndc80PGeNrMulEU%2Fuploads%2FquIUWfGcM5JtS2mLmNpm%2Fimage.png?alt=media\&token=2f9cff99-9a34-48c0-88b1-1287f4f2b6ae)

#### Set up MoneyCollect <mark style="color:blue;">`Server side`</mark>    <mark style="color:blue;">`Client side`</mark>

Firstly, you need a MoneyCollect account. [Register now](https://portal.moneycollect.com/registerr).

### **1. Set up Server-side**

If the client side wants to access most of the MoneyCollect Server API, it needs the dashboard to initiate a request through the private key.&#x20;

[Download ](https://github.com/MoneyCollect/moneycollect-api-android-demo/tree/mcappserver)the mock merchant portal interface code on github.

#### **1.1 Using your own key to** replace the public key and private key in the MobilePayController.java file&#x20;

```
//Your account PUBLIC_SECRET("Bearer "+PUBLIC_SECRET)
private static final String PUBLIC_SECRET = "Bearer live_pu_OGJ0EidwEg4GjymEiRD7cUBk7IQIYmhwhJlUM****";
//Your account PRIVATE_SECRET("Bearer "+PRVATE_SECRET)
private static final String PRIVATE_SECRET = "Bearer live_pr_OGJ0EidwEg4GjymEiRD4MRxBCo0OumdH6URv****";
```

{% hint style="info" %}
The format of PUBLIC\_SECRET & PRIVATE\_SECRET is（"Bearer"+PUBLIC\_SECRET）
{% endhint %}

#### 1.2 Modify server port（Default to be 9898）

```
server.port=9898
```

The merchant replaces <mark style="color:blue;">`the public key`</mark> and <mark style="color:blue;">`private key`</mark> in the code with their own,  and then switch on the server code's default port 9099 can be modified.（The dashboard interface address is the local ip:9898）

### **2. Set up Client-side**

Import MoneyCollect iOS sdk, and then initialize the sdk.

> #### **2.1 Installation**
>
> To integrate MoneyCollect into your Xcode project using CocoaPods, specify it in your Podfile:

```
pod 'MoneyCollect', '~> 0.0.1'
```

> #### **2.2** Initialize sdk
>
> Initialize MoneyCollect iOS sdk in the project AppDelegate.

```
/** API publishable Key */
@property (nonatomic,copy) NSString *publishableKey;

/** The customer IP address passed by the merchant*/
@property (nonatomic,copy) NSString *customerIPAddress;

/// Set publishable Key and customer IP Address
/// @param publishableKey publishable Key
/// @param customerIPAddress IP Address
- (void)setPublishableKey:(NSString * _Nonnull)publishableKey atCustomerIPAddress:(NSString *)customerIPAddress;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Initiate PublishableKey and IPAddress
    [[MCAPIClient shared] setPublishableKey:@"Bearer test_pu_1sWrsjQP9PJiCwGsYv3risSn8YBCIEMNoVFIo8eR6s" atCustomerIPAddress:@"http://192.168.2.100:9898/api"];
    
    return YES;
    
}
```

### **3.** Construct the data parameters to initiate transaction, and then start the payment activity

The merchant constructs the transaction request parameters and clicks the Checkout button to start the payment activity.（The details of using constructMCCreatePaymentParams method to construct data please refer to Example）

```
#pragma mark - Button Click Event
- (void)checkoutBtnClick:(UIButton *)sender
{
    // Initiate controller
    MCSelectPaymentCardVC *selectPaymentCardVC = [[MCSelectPaymentCardVC alloc] init];
    selectPaymentCardVC.delegate = self;

    // Build request parameters
    selectPaymentCardVC.customerID = [MCConfigurationFile getCustomerID];
    selectPaymentCardVC.billingDetails = [MCConfigurationFile getBillingDetailsModel];
    selectPaymentCardVC.createPaymentParams = [self constructMCCreatePaymentParams];
    
    // Load view
    [selectPaymentCardVC present:self];
}
```

After the customer completes the payment by clicking <mark style="color:purple;">`Pay Now`</mark> button, the payment activity will be dismissed and return to the Example's MCPaymentSheetCheckoutVC. At the same time，return the payment result responseObject through the proxy.

```
#pragma mark - MCSelectPaymentCardVCDelegate
- (void)successfulTransactionWithResponseObject:(NSDictionary *)responseObject
{
    // transaction status
    NSString *status = [[responseObject objectForKey:@"data"] objectForKey:@"status"];
    
    if ([status isEqualToString:@"succeeded"]) {
        
        NSLog(@"success");
        
    }else if ([status isEqualToString:@"failed"]) {
        
        NSLog(@"%@",[[responseObject objectForKey:@"data"] objectForKey:@"errorMessage"]);
        
    }else if ([status isEqualToString:@"pending"]) {
        
        NSLog(@"pending");
        
    }else if ([status isEqualToString:@"uncaptured"]) {
        
        NSLog(@"uncaptured");
        
    }else if ([status isEqualToString:@"canceled"]) {
        
        NSLog(@"canceled");
        
    }else {
        
        NSLog(@"pending");
        
    }
}
```

### **4. Additional testing resources**

There are several test cards you can use to make sure your integration is ready for production. Use them with any <mark style="color:purple;">`CVC`</mark>, <mark style="color:purple;">`postal code`</mark>, and <mark style="color:purple;">`future expiration date`</mark>.

<table><thead><tr><th width="173.5104880378872">Card Number</th><th width="188.87210677098545">Brand</th><th>DESCRIPTION</th></tr></thead><tbody><tr><td>4242 4242 4242 4242</td><td>Visa</td><td><mark style="color:green;">Succeeds</mark> and immediately processes the payment.</td></tr><tr><td>3566 0020 2036 0505</td><td>JCBA</td><td><mark style="color:green;">Succeeds</mark> and immediately processes the payment.</td></tr><tr><td>6011 1111 1111 1117</td><td>Discover</td><td><mark style="color:green;">Succeeds</mark> and immediately processes the payment.</td></tr><tr><td>3782 8224 6310 0052</td><td>American Express</td><td><mark style="color:green;">Succeeds</mark> and immediately processes the payment.</td></tr><tr><td>5555 5555 5555 4444</td><td>Mastercard</td><td><mark style="color:green;">Succeeds</mark> and immediately processes the payment.</td></tr><tr><td>4000002500003155</td><td>Visa</td><td>This card requires <mark style="color:orange;">3D</mark> authentication on all transaction</td></tr><tr><td>4000 0000 0000 0077</td><td>Visa</td><td>Always fails with a decline code of <mark style="color:red;"><code>declined</code></mark>.</td></tr></tbody></table>
{% endtab %}

{% tab title="Custom payment flow" %}

{% endtab %}
{% endtabs %}
