This is the code I'm using which is essentially the sample account creation code, but supplying an opaqueDataType as the paymentType.
public static CreateApplePayCustomerProfileResult Run(string ApiLoginID, string ApiTransactionKey, ApplePayPayment token, bool isLive)
{
var result = new CreateApplePayCustomerProfileResult();
result.DebugText += ("Create Apple Pay Profile Sample ");
result.DebugText += ("isLive == " + isLive + " ");
//comvert the "payment data token" back into JSON
var tokenjson = Newtonsoft.Json.JsonConvert.SerializeObject(token.paymentData);
//the base-64 encode it
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(tokenjson);
var token64 = System.Convert.ToBase64String(plainTextBytes);
// set whether to use the sandbox environment, or production enviornmentif (isLive)
if(isLive)
{
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.PRODUCTION;
}
else
{
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;
}
// define the merchant information (authentication / transaction id)
ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
{
name = ApiLoginID,
ItemElementName = ItemChoiceType.transactionKey,
Item = ApiTransactionKey
};
var applePay = new opaqueDataType {
dataDescriptor = "COMMON.APPLE.INAPP.PAYMENT",
dataValue = token64
};
paymentType ap = new paymentType { Item = applePay };
List<customerPaymentProfileType> paymentProfileList = new List<customerPaymentProfileType>();
customerPaymentProfileType apPaymentProfile = new customerPaymentProfileType();
apPaymentProfile.payment = ap;
paymentProfileList.Add(apPaymentProfile);
List<customerAddressType> addressInfoList = new List<customerAddressType>();
customerAddressType homeAddress = new customerAddressType();
homeAddress.firstName = "Tester";
homeAddress.lastName = "McTester";
homeAddress.address = "10900 NE 8th St";
homeAddress.city = "Seattle";
homeAddress.zip = "98006";
addressInfoList.Add(homeAddress);
customerProfileType customerProfile = new customerProfileType();
customerProfile.merchantCustomerId = "Test CustomerID";
customerProfile.email = "Tester@McTester.nowhere.test.com";
customerProfile.paymentProfiles = paymentProfileList.ToArray();
customerProfile.shipToList = addressInfoList.ToArray();
var request = new createCustomerProfileRequest { profile = customerProfile, validationMode = validationModeEnum.none };
// instantiate the controller that will call the service
var controller = new createCustomerProfileController(request);
controller.Execute();
// get the response from the service (errors contained if any)
createCustomerProfileResponse response = controller.GetApiResponse();
// validate response
if (response != null)
{
if (response.messages.resultCode == messageTypeEnum.Ok)
{
if (response.messages.message != null)
{
result.DebugText += ("Success!");
result.DebugText += ("Customer Profile ID: " + response.customerProfileId);
result.DebugText += ("Payment Profile ID: " + response.customerPaymentProfileIdList[0]);
result.DebugText += ("Shipping Profile ID: " + response.customerShippingAddressIdList[0]);
}
}
else
{
result.DebugText += ("Customer Profile Creation Failed.");
result.DebugText += ("Error Code: " + response.messages.message[0].code);
result.DebugText += ("Error message: " + response.messages.message[0].text);
}
}
else
{
if (controller.GetErrorResponse().messages.message.Length > 0)
{
result.DebugText += ("Customer Profile Creation Failed.");
result.DebugText += ("Error Code: " + response.messages.message[0].code);
result.DebugText += ("Error message: " + response.messages.message[0].text);
}
else
{
result.DebugText += ("Null Response.");
}
}
return result;
}