paypal_refund_id = $refundID; $refundObj->refund_amount = (float)$eventData['resource']['amount']['value']; $refundObj->currency_code = $eventData['resource']['amount']['currency_code']; if (isset($eventData['resource']['note_to_payer'])) { $refundObj->refund_reason = $eventData['resource']['note_to_payer']; } $refundObj->response = json_encode($eventData); $refundObj->refund_status = $eventData['resource']['status']; $refundObj->save(); } public function captureDenied($eventData) { $transaction_id = $eventData['resource']['id']; if ($transactionData = WKPayPalCommerceOrder::getTransactionDetailsByPaypalTransaction( $transaction_id )) { $cartID = $transactionData['id_cart']; // if orders found for the transaction then set the order status if ($orders = WkPaypalCommerceHelper::getOrdersByCartId($cartID)) { foreach ($orders as $order) { $this->updatePaymentStatus( (int)Configuration::get('PS_OS_ERROR'), $order['id_order'] ); } } $ppOrderStatus = $eventData['resource']['status']; WKPayPalCommerceOrder::updateOrderCapturePaypalOrderStatus($transaction_id, $ppOrderStatus); } } public function orderCompleted($eventData) { $purchaseUnits = $eventData['resource']['purchase_units']; $payment_status = $eventData['resource']['status']; foreach ($purchaseUnits as $purchase) { $transaction_id = $purchase['payments']['captures'][0]['id']; if ($transactionData = WKPayPalCommerceOrder::getTransactionDetailsByPaypalTransaction( $transaction_id )) { // Check if PayPal order is already finished with status COMPLETED if ($transactionData['pp_payment_status'] != self::WK_PAYPAL_COMMERCE_PAYMENT_STATUS_COMPLETED) { // if order completed then change the status of the order if ($eventData['event_type'] == self::WK_PAYPAL_COMMERCE_EVENT_TYPE_ORDER_COMPLETED) { $cartID = $transactionData['id_cart']; $objCart = new Cart($cartID); $capturedAmount = isset($purchase['payments']['captures'][0]['amount']['value']) ? (float)$purchase['payments']['captures'][0]['amount']['value'] : 0; $fullTotal = (float)$objCart->getOrderTotal(true, Cart::BOTH); $orderStatus = $capturedAmount >= $fullTotal ? Configuration::get('PS_OS_PAYMENT_ACCEPTED') : Configuration::get('PS_OS_PARTIAL_PAYMENT_ACCEPTED'); if ($orders = WkPaypalCommerceHelper::getOrdersByCartId($cartID)) { foreach ($orders as $order) { $this->updatePaymentStatus( (int)$orderStatus, $order['id_order'] ); } } } } WKPayPalCommerceOrder::updateOrderPaypalOrderStatus($transaction_id, $payment_status, $eventData['resource']); } } } public function captureCompleted($eventData) { $transaction_id = $eventData['resource']['id']; if ($transactionData = WKPayPalCommerceOrder::getTransactionDetailsByPaypalTransaction( $transaction_id )) { $cartID = $transactionData['id_cart']; $objCart = new Cart($cartID); $capturedAmount = isset($eventData['resource']['amount']['value']) ? (float)$eventData['resource']['amount']['value'] : 0; $fullTotal = (float)$objCart->getOrderTotal(true, Cart::BOTH); $orderStatus = $capturedAmount >= $fullTotal ? Configuration::get('PS_OS_PAYMENT_ACCEPTED') : Configuration::get('PS_OS_PARTIAL_PAYMENT_ACCEPTED'); if ($orders = WkPaypalCommerceHelper::getOrdersByCartId($cartID)) { foreach ($orders as $order) { $this->updatePaymentStatus( (int)$orderStatus, $order['id_order'] ); } } $ppOrderStatus = $eventData['resource']['status']; WKPayPalCommerceOrder::updateOrderCapturePaypalOrderStatus($transaction_id, $ppOrderStatus); } } /** * updatePaymentStatus * @param int $id_order_state Order Status ID * @param int $id_order Order ID * @return void */ public function updatePaymentStatus($id_order_state, $id_order) { $order = new Order($id_order); $currentOrderState = $order->getCurrentOrderState(); if ($currentOrderState->id != $id_order_state) { $useExistPayment = false; if (!$order->hasInvoice()) { $useExistPayment = true; } $orderHistory = new OrderHistory(); $orderHistory->id_order = (int)$id_order; $orderHistory->changeIdOrderState( (int)$id_order_state, $order, $useExistPayment ); $orderHistory->addWithemail(true, null); } } }