Develop Secure Code
getSupportedPaymentMethods()
collectPayment()
Collect a payment using the selected payment method.
1import { getPaymentsService } from 'lightning/mobileCapabilities';
2collectPayment(options: CollectPaymentOptions): Promise<[CollectPaymentResult]>CollectPaymentOptions-An object described by these attributes.
amount-(Required) A text field that shows the amount intended to be collected in a decimal format (for example, 150.00).paymentMethod-(Required) A text field that shows the requested payment method (for example, TAP_TO_PAY).currencyIsoCode-(Required) A text field that represents the currency ISO code.merchantAccountId-(Required) A text field that represents the ID of the Merchant Account object.merchantName-(Required) A text field that shows the text that’s presented as the product/service name being paid for (for example, “Power Connector”).payerAccountId-(Required) A text field that represents the ID of the Account object requesting to collect the payment.sourceObjectIds-(Optional) A text field that represents the ID of the originating object for the payment (for example, ServiceAppointment ID, WorkOrder ID).permissionRationaleText-(Optional) A text field that’s presented to the user if permission is missing (for example, location permission) and must be requested from the user. Defaults to a predefined text if it’s empty.A Promise object that resolves as a CollectPaymentResult object. If there’s an error, a rejected promise returns the error type of PaymentsServiceFailure.
1myPaymentsService.collectPayments(options).then((results) => {
2 const collectPaymentResult = JSON
3 .parse(JSON.stringify(collectPaymentResult, undefined, 2));
4 var msg = "Confirmation Status: " + confirmationStatus + ",
5 Confirmation ID: " + confirmationId; console.log(msg);
6 }
7 )
8 .catch((error) => {
9 const msg = `Failed to collect payment: ${JSON.stringify(error)}`;
10 console.log(msg);
11 }
12 );