mercado pago end
This commit is contained in:
parent
02b77670e2
commit
7012a68265
|
@ -1,6 +1,6 @@
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- PayPal, Stripe and Mollie Integration
|
- PayPal, Stripe, Mollie and MercadoPago Integration
|
||||||
- Hourly, Weekely, Monthly, Quarterly and Annual billing Cycles
|
- Hourly, Weekely, Monthly, Quarterly and Annual billing Cycles
|
||||||
- Referral System
|
- Referral System
|
||||||
- Partner System
|
- Partner System
|
||||||
|
|
|
@ -60,8 +60,8 @@ class MercadoPagoExtension extends AbstractExtension
|
||||||
[
|
[
|
||||||
'title' => "Order #{$payment->id} - " . $shopProduct->name,
|
'title' => "Order #{$payment->id} - " . $shopProduct->name,
|
||||||
'quantity' => 1,
|
'quantity' => 1,
|
||||||
// convert shopProduct to float(this is string)
|
// convert to float
|
||||||
'unit_price' => floatval($shopProduct->getTotalPrice()),
|
'unit_price' => floatval($totalPriceString),
|
||||||
'currency_id' => $shopProduct->currency_code,
|
'currency_id' => $shopProduct->currency_code,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@ -111,54 +111,29 @@ class MercadoPagoExtension extends AbstractExtension
|
||||||
static function Webhook(Request $request): JsonResponse
|
static function Webhook(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
$topic = $request->input('topic');
|
$topic = $request->input('topic');
|
||||||
$msg = 'unset';
|
|
||||||
$status = 400;
|
|
||||||
if ($topic === 'merchant_order') {
|
if ($topic === 'merchant_order') {
|
||||||
$msg = 'ignored';
|
// ignore other types IPN
|
||||||
$status = 200;
|
return response()->json(['success' => true]);
|
||||||
} else if ($topic === 'payment') {
|
} else if ($topic === 'payment') {
|
||||||
$msg = 'ignored';
|
// ignore other types IPN
|
||||||
$status = 200;
|
return response()->json(['success' => true]);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
$notificationId = $request->input('data.id') ?? $request->input('id') ?? $request->input('payment_id') ?? 'unknown';
|
$notificationId = $request->input('data.id') ?? $request->input('id') ?? $request->input('payment_id') ?? 'unknown';
|
||||||
if ($notificationId == 'unknown') {
|
if ($notificationId == 'unknown') {
|
||||||
$msg = 'unknown payment.';
|
return response()->json(['success' => false]);
|
||||||
$status = 400;
|
|
||||||
} else if ($notificationId == '123456') {
|
} else if ($notificationId == '123456') {
|
||||||
$msg = 'MercadoPago api test';
|
// mercado pago api test
|
||||||
$status = 200;
|
return response()->json(['success' => true]);
|
||||||
} else {
|
} else {
|
||||||
$MpPayment = self::MpPayment($notificationId, true);
|
self::MpPayment($notificationId, true);
|
||||||
switch ($MpPayment) {
|
|
||||||
case "paid":
|
|
||||||
$msg = $MpPayment;
|
|
||||||
$status = 200;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "cancelled":
|
|
||||||
$msg = $MpPayment;
|
|
||||||
$status = 200;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "processing":
|
|
||||||
$msg = $MpPayment;
|
|
||||||
$status = 200;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$msg = 'unknown';
|
|
||||||
$status = 400;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
Log::error('MercadoPago Webhook(IPN) Payment: ' . $ex->getMessage());
|
Log::error('MercadoPago Webhook(IPN) Payment: ' . $ex->getMessage());
|
||||||
$msg = 'error';
|
return response()->json(['success' => false]);
|
||||||
$status = 500;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$response = new JsonResponse($msg, $status);
|
return response()->json(['success' => true]);
|
||||||
return $response;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Mercado Pago Payment checker
|
* Mercado Pago Payment checker
|
||||||
|
@ -166,7 +141,6 @@ class MercadoPagoExtension extends AbstractExtension
|
||||||
private function MpPayment(string $paymentID, bool $notification): string
|
private function MpPayment(string $paymentID, bool $notification): string
|
||||||
{
|
{
|
||||||
$MpResponse = "unknown";
|
$MpResponse = "unknown";
|
||||||
$payment = "unknown";
|
|
||||||
$url = "https://api.mercadopago.com/v1/payments/" . $paymentID;
|
$url = "https://api.mercadopago.com/v1/payments/" . $paymentID;
|
||||||
$settings = new MercadoPagoSettings();
|
$settings = new MercadoPagoSettings();
|
||||||
$response = Http::withHeaders([
|
$response = Http::withHeaders([
|
||||||
|
|
|
@ -6,13 +6,13 @@ class CreateMercadoPagoSettings extends SettingsMigration
|
||||||
{
|
{
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
$this->migrator->addEncrypted('mpago.access_token', null);
|
$this->migrator->addEncrypted('mercadopago.access_token', null);
|
||||||
$this->migrator->add('mpago.enabled', false);
|
$this->migrator->add('mercadopago.enabled', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function down(): void
|
public function down(): void
|
||||||
{
|
{
|
||||||
$this->migrator->delete('mpago.access_token');
|
$this->migrator->delete('mercadopago.access_token');
|
||||||
$this->migrator->delete('mpago.enabled');
|
$this->migrator->delete('mercadopago.enabled');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue