Fatal error: Uncaught OmiseNotFoundException: customer was not found in

Hi folks !! Anyone know why I keep getting this error ? sorry Iā€™m a newbie.
Please help. :sob::sob:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
    <script src="https://cdn.omise.co/card.js"></script>
</head>
<body>
    <form id="checkoutForm" method="POST" action="checkout.php">
        <script type="text/javascript" src="https://cdn.omise.co/card.js"
                data-key="pkey_test_5ibroxfwp5ydmnnfti9"
                data-amount="12345"
                data-button-label="Pay now"
                data-submit-label="Submit"
                data-currency="THB"
                data-default-payment-method="credit_card"
                >
        </script>
      </form>
</body>
</html>
<?php 
require './omise-php/lib/Omise.php';

define('OMISE_PUBLIC_KEY', 'pkey_test_5ibroxfwp5ydmnnfti9');
define('OMISE_SECRET_KEY', 'skey_test_5i4r1ec4w46bftsb329');

$scheduler = OmiseCharge::schedule(array(
'amount' => 32000,
'currency' => 'thb',
'card' => $_POST['omiseToken'],
'customer' => 'cust_test_58e7b94d2wfmfn6p2x1',
'description' => 'Membership fee'
));

$schedule = $scheduler->every(1)
                      ->months('2nd_monday')
                      ->startDate('2020-09-17')
                      ->endDate('2022-09-17')
                      ->start();



echo '<pre>';
print_r ($_POST);
echo '</pre>';

echo '<pre>';
print_r ($charge);
echo '</pre>';

I think the problem is that you are passing a token directly to the charge schedule when instead you should be passing a card. You use the token generated by Omise.js to save a card on the customer. Then you use the card and customer ids together to create a recurring charge on the customer.

Also, please use https://cdn.omise.co/omise.js and not https://cdn.omise.co/card.js in your JavaScript (see: https://www.omise.co/omise-js)

This example is in Python and is a normal charge, but it shows that when you want to create a charge and what you have is a token and a customer, you have to create a new card on the customer first and then charge that card.

Hope this helps!

1 Like