Initiating a Payment for Apple Pay

The beginPayment method will initiate a payment from the application upon tapping the Pay button. If Apple Pay is available then the Apple Pay summary sheet opens.

You need to declare the PaysafePaymentAuthorizationProcessDelegate in your application code (header file) when calling the SDK. In addition, you need to pass a delegate reference from your application to the SDK in order to get the response from the SDK.

self.PaysafepaymentObj.authDelegate = self;
[self.PaysafepaymentObj beginPayment:self delgate:self.PaysafeAuthController withRequestData:[self createDataDictonary] withCartData:[self cartData]];
appDelegate.PaysafepaymentObj?.authDelegate = self
appDelegate.PaysafepaymentObj?.beginPayment(self, delgate: appDelegate.PaysafeApplePaySDKObj, withRequestData: createDataDictonary(), withCartData: createCartData())

Passing Data from the App to the SDK

In order to pass data from the merchant application to the SDK, you must create and call two internal methods: createDataDictionary and cartData. These two methods will create dictionaries or data sets to include in the beginPayment method (mentioned above).

-(NSMutableDictionary *)createDataDictonary
 {
    // Merchant shipping methods
    NSString *shippingMethodName = @"Llama California Shipping";
    NSString *shippingMethodAmount = @"1.00";
    NSString *shippingMethodDescription = @"3-5 Business Days";

    NSDictionary *shippingMethod = [NSDictionarydictionaryWithObjectsAndKeys:shippingMethodName,@"shippingName",shippingMethodAmount,@"shippingAmount", shippingMethodDescription,@"shippingDes", nil];
    NSString *envType = @"TEST_ENV";  //PROD_ENV  - in framework we used test & prod environment url's to communicate with Paysafe.
    NSString *timeIntrval = @"30.0";
    NSDictionary *envSettingDict = [NSDictionary dictionaryWithObjectsAndKeys :envType,@"EnvType",timeIntrval,@"TimeIntrval",nil];
    NSMutableDictionary *finalDataDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:shippingMethod,@"ShippingMethod ",envSettingDict,@"EnvSettingDict", nil ];
    return finalDataDictionary;
}
-(NSDictionary*)cartData{
    // Merchant Cart data
    NSString *cartID =@"123423";
    NSString *cartTitle = @"TShirt";
    NSString *cartCost = @"4";
    NSString *cartDiscount = @"3";
    NSString *cartShippingCost =@"2";
    NSString *payTo =@"Llama Services, Inc.";

    NSDictionary *cartDictonary = [NSDictionary dictionaryWithObjectsAndKeys:cartID,@"CartID",cartTitle,@"CartTitle",cartCost,@"CartCost",cartDiscount, @"CartDiscount", cartShippingCost,@"CartShippingCost" , payTo, @"PayTo", nil];
    return cartDictonary;
}
func createDataDictonary() -> Dictionary<String, Dictionary <String,String>>{
        // Merchant shipping methods
        var shippingMethod1Dictionary: [String: String] = ["shippingName":"Llama California Shipping", "shippingAmount":"1.00", "shippingDes":"3-5 Business Days"
        var envType:String = "TEST_ENV"; //PROD_ENV  - in framework we used test & prod environment url's to communicate with Paysafe.

        var timeIntrval:String = "30.0";  //Time interval for connection to the Paysafe server
        var enviDictionary: [String: String] = ["EnvType":envType, " TimeIntrval ":timeIntrval]
        var dataDictonary: [String: Dictionary] = ["ShippingMethod  ": shippingMethod1Dictionary,"EnvSettingDict": enviDictionary]
        return dataDictonary
}

func createCartData() -> Dictionary<String, String>{
        var cartDictonary: [String: String] = ["CartID":"123423", "CartTitle":"TShirt", "CartCost": "3", "CartDiscount": "1" , "CartShippingCost":"2","PayTo":"Llama Services, Inc."]
        return cartDictonary;
}
Shipping Dictionary
Key Description
shippingName Shipping method name
shippingAmount Shipping amount
shippingDes Shipping description
Environment Settings Dictionary
Key Description
shippingName Shipping method name
shippingAmount Shipping amount
shippingDes Shipping description
Cart Dictionary
Key Description
CartID Cart ID
CartTitle Cart title
CartCost Cart cost
CartDiscount Cart discount
CartShippingCost Cart shipping cost
PayTo Cart amount pay to

The keys above have been used in the SDK to get values from the beginPayment dictionaries. You need to use the same keys in your application code when creating data dictionaries for shipping, environment, and cart details.

Making the Payment

If Apple Pay is available, PaysafePaymentAuthorizationProcess will launch an Apple Pay View Controller summary sheet, as in the image below:

After selecting Pay, the SDK will communicate with the Apple Pay server to get an Apple Pay token (using the beginPayment method). If there are no issues, your application will receive the Apple Pay token in a response from the Apple Pay server.

By using this Apple Pay token as a request, the SDK will communicate with the Paysafe server to get a Paysafe token.

  • On the simulator, you will receive a fake token to communicate with Paysafe.

    PaysafeMockPaymentAuthorizationProcess

  • On real devices that support Apple Pay, you will receive an Apple Pay payment token from Apple to communicate with Paysafe.

    PaysafePaymentAuthorizationProcess.

Click here to view the countries where Paysafe currently supports Apple Pay.

Did you find this page useful?