if (![MFMailComposeViewController canSendMail]) { UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Cannot start transaction!" message:@"No mail account is set up. Please open Settings and configure your mail account before doing a transaction." preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* settingsAction = [UIAlertAction actionWithTitle:@"Settings" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; }]; UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [self dismissViewControllerAnimated:YES completion:NULL]; }]; [alert addAction:settingsAction]; [alert addAction:cancelAction]; [self presentViewController:alert animated:YES completion:NULL]; return; }
if (transaction.status == MPTransactionStatusApproved) { NSString* merchantName = @"payworks"; NSString* merchantStreet = @"Demo Street 12"; NSString* merchantZipAndTown = @"12601 City"; NSString* merchantCountry = @"Country"; MPReceipt* receipt = [paymentProcess.receiptFactory customerReceiptForTransaction:transaction]; if ([MFMailComposeViewController canSendMail]) { UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Receipt?" message:nil preferredStyle:UIAlertActionStyleDefault]; UIAlertAction* receiptAction = [UIAlertAction actionWithTitle:@"Send a receipt" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { MFMailComposeViewController* mailViewController = [[MFMailComposeViewController alloc] init]; mailViewController.mailComposeDelegate = self; [mailViewController setSubject:[NSString stringWithFormat:@"%@ - %@", merchantName, receipt.transactionType.value]]; // Create Message body NSMutableString* paymentDetails = [NSMutableString string]; for (MPReceiptLineItem* line in receipt.paymentDetails) { [paymentDetails appendString:[NSString stringWithFormat:@"%@: %@\n", line.label, line.value]]; } NSMutableString* clearingDetails = [NSMutableString string]; for (MPReceiptLineItem* line in receipt.clearingDetails) { [clearingDetails appendString:[NSString stringWithFormat:@"%@: %@\n", line.label, line.value]]; } NSString* messageBody = [NSString stringWithFormat:@"%@\n%@\n%@\n%@\n\n%@ %@\n\n%@\n\n%@\n%@\n\n%@ %@\n\n%@%@: %@", merchantName, merchantStreet, merchantZipAndTown, merchantCountry, receipt.receiptType.value, receipt.transactionType.value, receipt.amountAndCurrency.value, paymentDetails, receipt.statusText.value, receipt.date.value, receipt.time.value, clearingDetails, receipt.identifier.label, receipt.identifier.value]; [mailViewController setMessageBody:messageBody isHTML:NO]; [self presentViewController:mailViewController animated:YES completion:NULL]; }]; UIAlertAction* continueAction = [UIAlertAction actionWithTitle:@"Continue without receipt" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [self dismissViewControllerAnimated:YES completion:NULL]; }]; [alert addAction:receiptAction]; [alert addAction:continueAction]; [self presentViewController:alert animated:YES completion:NULL]; } else { UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Cannot send receipt!" message:@"No mail account is set up." preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [self dismissViewControllerAnimated:YES completion:NULL]; }]; [alert addAction:cancelAction]; [self presentViewController:alert animated:YES completion:NULL]; } }
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { [self dismissViewControllerAnimated:YES completion:NULL]; }