. */ /* */ /*************************************************************************************/ namespace PayPal\Controller; use Monolog\Logger; use PayPal\Event\PayPalEvents; use PayPal\Event\PayPalOrderEvent; use PayPal\Exception\PayPalConnectionException; use PayPal\Model\PaypalOrderQuery; use PayPal\Model\PaypalPlanQuery; use PayPal\PayPal; use PayPal\Service\PayPalAgreementService; use PayPal\Service\PayPalLoggerService; use Propel\Runtime\Propel; use Thelia\Controller\Front\BaseFrontController; use Thelia\Core\Event\Order\OrderEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\HttpFoundation\Request; use Thelia\Core\Translation\Translator; use Thelia\Model\OrderStatusQuery; /** * Class PayPalWebHookController * @package PayPal\Controller */ class PayPalWebHookController extends BaseFrontController { const HOOK_BILLING_PLAN_CREATED = 'BILLING.PLAN.CREATED'; const HOOK_BILLING_PLAN_UPDATED = 'BILLING.PLAN.UPDATED'; const HOOK_BILLING_SUBSCRIPTION_CREATED = 'BILLING.SUBSCRIPTION.CREATED'; const HOOK_PAYMENT_SALE_COMPLETED = 'PAYMENT.SALE.COMPLETED'; const HOOK_PAYMENT_SALE_DENIED = 'PAYMENT.SALE.DENIED'; //Classic PayPal payment const RESOURCE_TYPE_SALE = 'sale'; //Planified payment const RESOURCE_TYPE_PLAN = 'plan'; const RESOURCE_TYPE_AGREEMENT = 'agreement'; /** * Example of array received in posted params : * * * Array ( * 'id' => 'WH-0LU96374794024348-4WG31854RU4949452', * 'event_version' => 1.0, * 'create_time' => '2017-02-03T15:31:29Z', * 'resource_type' => 'plan', * 'event_type' => 'BILLING.PLAN.CREATED', * 'summary' => 'A billing plan was created', * 'resource' => Array ( * 'merchant_preferences' => Array ( * 'setup_fee' => Array ( * 'currency' => 'EUR', * 'value' => 0 * ), * 'return_url' => 'http://25b3ee89.ngrok.io/thelia_2_3_3/web/module/paypal/agreement/ok/208', * 'cancel_url' => 'http://25b3ee89.ngrok.io/thelia_2_3_3/web/module/paypal/agreement/ko/208', * 'auto_bill_amount' => 'NO', * 'initial_fail_amount_action' => 'CONTINUE', * 'max_fail_attempts' => 0 * ), * 'update_time' => '2017-02-03T15:31:29.348Z', * 'create_time' => '2017-02-03T15:31:29.348Z', * 'name' => 'plan for order 208', * 'description' => false, * 'links' => Array ( * 0 => Array ( * 'href' => 'api.sandbox.paypal.com/v1/payments/billing-plans/P-2DV20774VJ3968037ASNA3RA', * 'rel' => 'self', * 'method' => 'GET' * ) * ), * 'payment_definitions' => Array ( * 0 => Array ( * 'name' => 'payment definition for order 208', * 'type' => 'REGULAR', * 'frequency' => 'Day', * 'frequency_interval' => 1, * 'amount' => Array ( * 'currency' => 'EUR', * 'value' => 3.9 * ), * 'cycles' => 5, * 'charge_models' => Array ( * 0 => Array ( * 'type' => 'SHIPPING', * 'amount' => Array ( * 'currency' => 'EUR', * 'value' => 0 * ), * 'id' => 'CHM-26B03456D8799461GASNA3RA' * ) * ), * 'id' => 'PD-3FB00313143031422ASNA3RA' * ) * ), * 'id' => 'P-2DV20774VJ3968037ASNA3RA', * 'state' => 'CREATED', * 'type' => 'FIXED' * ), * 'links' => Array ( * 0 => Array ( * 'href' => 'https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-0LU96374794024348-4WG31854RU4949452', * 'rel' => 'self', * 'method' => 'GET' * ), * 1 => Array ( * 'href' => 'https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-0LU96374794024348-4WG31854RU4949452/resend', * 'rel' => 'resend', * 'method' => 'POST' * ) * ) * ); */ public function allAction() { $eventType = $this->getRequest()->request->get('event_type'); $resource = $this->getRequest()->request->get('resource'); $resourceType = $this->getRequest()->request->get('resource_type'); $details = [ 'request' => $this->getRequest()->request->all() ]; $params = [ 'hook' => $eventType ]; $con = Propel::getConnection(); $con->beginTransaction(); try { $title = $this->getTitle($this->getRequest()); if (is_array($resource)) { switch (strtolower($resourceType)) { case self::RESOURCE_TYPE_SALE: if (isset($resource['parent_payment'])) { $params = $this->getParamsForSale($resource['parent_payment'], $params, $eventType); } if (isset($resource['billing_agreement_id'])) { $params = $this->getParamsForAgreement($resource['billing_agreement_id'], $params); } break; case self::RESOURCE_TYPE_PLAN: if (isset($resource['id'])) { $params = $this->getParamsForPlan($resource['id'], $params); } break; case self::RESOURCE_TYPE_AGREEMENT: if (isset($resource['id'])) { $params = $this->getParamsForAgreement($resource['id'], $params); } break; default: break; } } PayPalLoggerService::log( '