I have a few questions:
Can I store the credit card/paypal method in sale but also prevent duplicates? OR do duplicates just create an error when using storeInVaultOnSuccess. Will a "duplicate method" error cause sale to fail?
Can I create a customer with Braintree_Transaction::sale? Will a "duplicate customer" error cause sale to fail?
Is there a way to combine to do a "either/or" for paymentMethodNonce and paymentMethodToken?
Lastly security question. Does Braintree make sure the paymenthMethodToken for a customer matches the customerId of the sale? To ensure a token for one customer method cannot be used to complete sale for another customer.
if($paymentMethodNonce){
if($save){
$create=Braintree_PaymentMethod::create([
"customerId"=>$customerId,
"paymentMethodNonce"=>$paymentMethodNonce,
"options"=>["failOnDuplicatePaymentMethod"=>true]
]);
}
$sale=Braintree_Transaction::sale([
"amount"=>$cost,
"paymentMethodNonce"=>$paymentMethodNonce,
"customerId"=>$customerId
]);
}
else if($paymentMethodToken){
$sale=Braintree_Transaction::sale([
"amount"=>$cost,
"paymentMethodToken"=>$paymentMethodToken,
"customerId"=>$customerId
]);
}