Customers
Customers
A customer is the record PayMongo keeps for a person you charge more than once: a name, an email, a phone, and the device PayMongo contacts them on. Cards are saved against it, and subscriptions bill it. Every customer here is fictional, and its personal fields are masked in the request and response, because a real customer's would be personal data.
Every demonstration here makes a real PayMongo API call in test mode. Nothing is simulated, and no real money moves.
Create customer
Create a fictional customer. The email and phone are fresh on every visit, because PayMongo requires them to be unique per customer.
Test mode: PayMongo rejects an email or phone another customer on the account already has. The default device is email or phone.
use Luigel\Paymongo\Facades\Paymongo;
$customer = Paymongo::customers()->create(
attributes: [
'first_name' => '••••',
'last_name' => '••••',
'email' => '••••',
'phone' => '••••',
'default_device' => 'email',
],
);Retrieve customer
Fetch a customer to see its default device and default payment method.
use Luigel\Paymongo\Facades\Paymongo;
$customer = Paymongo::customers()->retrieve(
id: '{customer id}',
);Update customer
Change a customer's name. Only the fields sent are changed.
use Luigel\Paymongo\Facades\Paymongo;
$customer = Paymongo::customers()->update(
id: '{customer id}',
attributes: [
'first_name' => '••••',
'last_name' => '••••',
],
);Delete customer
Delete a customer. The package returns true, since a failed deletion throws instead.
use Luigel\Paymongo\Facades\Paymongo;
$customer = Paymongo::customers()->delete(
id: '{customer id}',
);List saved payment methods
Fetch the payment methods saved against a customer. PayMongo returns them all at once, not as a cursor page, and the package returns a plain array. The summary names each by the pm_ id of the payment method it wraps, which is what removing it takes; the id in the JSON is the saved record's own.
Test mode: A new customer has no saved payment methods. PayMongo saves a card against a customer when a payment intent created with setup_future_usage for that customer succeeds, and card vaulting must be enabled on the account.
use Luigel\Paymongo\Facades\Paymongo;
$customer = Paymongo::customers()->paymentMethods(
customerId: '{customer id}',
);Remove a saved payment method
Remove a saved payment method from a customer. Once removed, it cannot be used again without saving it anew.
Test mode: PayMongo takes the payment method's own identifier here, the pm_ one a listed saved payment method carries as payment_method_id. It returns 404 when that payment method is not saved against the customer.
use Luigel\Paymongo\Facades\Paymongo;
$customer = Paymongo::customers()->deletePaymentMethod(
customerId: '{customer id}',
paymentMethodId: '{payment_method id}',
);