How to save form in database if payment is successful

Hello, after several attempts I am unable to automatically save the form in the database if the payment is validated.

I wanted at the time of the payment button, when the customer has finished his order and filled in the form, that the form is automatically saved in the database only if the payment is validated.

Here is my code below

import {createMyPayment} from ‘backend/pay’ ;
import wixPay from ‘wix-pay’ ;

export function button100_click(event) {
createMyPayment($w( ‘#TotalPrice’ ).text,$w( ‘#TotalPrice’ ).text)
.then( (payment) => {
wixPay.startPayment(payment.id, {
})

    .then( (result) => { 

if (result.status === “Successful” ) {

      }  **else if**  (result.status ===  "Pending" ) { 
          $w( "#dataset1" ).save(); 
      } 
  } ); 
} ); 

}


@visit360test Not knowing anything about how you have the backend function constructed, at a glance it looks like a save is not happening upon a payment that has the status of “Successful”, only a “Pending” one. Give this code a try, and notice the console.log placed before the if statement that will verify for you whether or not the createMyPayment backend function and the startPayment function are doing what you expect.

console.log(result.status);
 if (result.status === "Successful") {
     $w("#dataset1").save();
       } else if (result.status === "Pending") {
              $w("#dataset1").save();
       }