How can I send receipts without a backend?

If you don't want to build a backend for sending receipts, you can instead open the email app of iOS/Android.
On iOS, use MFMailComposeViewController. On Android, use an intent.
On iOS, advise the merchant to setup the mail client on his device before starting a transaction:
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; }
Here is the sample code for a quick, compliant receipt on iOS.Add the following codein the
transactionCompleted
callback.
Make sure that you load the correct values for the merchant name, street, zip and town, and country from your backend.
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]; } }
Make sure to close the mail view:
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { [self dismissViewControllerAnimated:YES completion:NULL]; }