email * in link payment #510
Replies: 2 comments 2 replies
-
version 2:
|
Beta Was this translation helpful? Give feedback.
2 replies
-
Solution for email force, <?php
require 'vendor/autoload.php'; // Carrega o autoload gerado pelo Composer
use MercadoPago\MercadoPagoConfig;
use MercadoPago\Client\Payment\PaymentClient;
use MercadoPago\Client\Preference\PreferenceClient;
use MercadoPago\Exceptions\MPApiException;
use MercadoPago\Client\Common\RequestOptions;
use MercadoPago\Resources\MerchantOrder\Item;
use MercadoPago\Resources\Preference;
// Configure suas credenciais do Mercado Pago
MercadoPagoConfig::setAccessToken($_ENV['MERCADOPAGO_TOKEN']);
function createPreferenceRequest($items, $payer): array
{
$paymentMethods = [
"excluded_payment_methods" => [],
"installments" => 12,
"default_installments" => 1
];
$backUrls = array(
'success' => 'google.com',
'failure' => 'google.com'
);
$request = [
"items" => $items,
"payer" => $payer,
"payment_methods" => $paymentMethods,
"back_urls" => $backUrls,
"statement_descriptor" => "NAME_DISPLAYED_IN_USER_BILLING",
"external_reference" => "1234567890",
"expires" => false,
"auto_return" => 'approved',
];
return $request;
}
// Step 3: Initialize the API client
// Fill the data about the product(s) being pruchased
$product1 = array(
"id" => "1234567890",
"title" => "Product 1 Title",
"description" => "Product 1 Description",
"currency_id" => "BRL",
"quantity" => 12,
"unit_price" => 9.90
);
// Mount the array of products that will integrate the purchase amount
$items = array($product1);
$payer = array(
"email" => 'required', // <---- Solution Force mail
);
// Create the request object to be sent to the API when the preference is created
$request = createPreferenceRequest($items, $payer);
// Instantiate a new Preference Client
$client = new PreferenceClient();
try {
// Send the request that will create the new preference for user's checkout flow
$preference = $client->create($request);
// Useful props you could use from this object is 'init_point' (URL to Checkout Pro) or the 'id'
echo "<pre>";
print_r($preference);
} catch (MPApiException $e) {
// Here you might return whatever your app needs.
// We are returning null here as an example.
echo "Status code: " . $e->getApiResponse()->getStatusCode() . "\n";
echo "Content: ";
var_dump($e->getApiResponse()->getContent());
echo "\n";
} ?> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there a way to generate a payment link that requires the buyer to enter their email address? How to get this email later?
Beta Was this translation helpful? Give feedback.
All reactions