Yordan Milenkov
Forum Replies Created
-
Forum: Plugins
In reply to: [Payment Plugins Braintree For WooCommerce] do_action on Disputeif(isset($notification)){ add_action( 'wc_braintree_webhook_notification_' . $notification->kind, 'my_mybraintree_webhook_notification_handler', 10, 2); } function my_mybraintree_webhook_notification_handler( $notification, $request ) { file_put_contents('./log_my_braintree_webhook_notification_handler_'.date("j.n.Y").'.log', 'my_braintree_webhook_notification_handler $request: '.json_encode($request).PHP_EOL, FILE_APPEND); file_put_contents('./log_my_braintree_webhook_notification_handler_'.date("j.n.Y").'.log', 'my_braintree_webhook_notification_handler $notification: '.json_encode($notification).PHP_EOL, FILE_APPEND); }Or like this.
No any log…Forum: Plugins
In reply to: [Payment Plugins Braintree For WooCommerce] do_action on DisputeSorry for the delay!
I’m trying to put a new hook in my php file in plugins directory, but either nothing happens or the whole site breaks.
I try things like:
add_action( 'wc_braintree_webhook_notification_CHECK' , 'my_function', 10, 1 ); function my_function($request){ file_put_contents('./log_wc_braintree_webhook_notification_check_'.date("j.n.Y").'.log', 'wc_braintree_webhook_notification_check: '.json_encode($request).PHP_EOL, FILE_APPEND); }Please, provide some examples!
Regards!
Forum: Plugins
In reply to: [Braintree for WooCommerce Payment Gateway] Braintree WebhookIndeed, because this is a different plugin. You can find Braintree for WooCommerce Payment Gateway‘s support documentation below for your reference:
https://woocommerce.com/document/woocommerce-gateway-paypal-powered-by-braintree/
Hope this helps!
That is exactly my question.
I can’t find such a setting in this documentation.
And that’s why I ask where to look for it?Forum: Plugins
In reply to: [Braintree for WooCommerce Payment Gateway] Braintree WebhookOops, My mistake 🙂 Thank you so much!
Wrong screenshot…
But I can’t find similar settings and Webhook URL in
Braintree for WooCommerce Payment Gateway
By WooCommerce- This reply was modified 3 years, 3 months ago by Yordan Milenkov.
Forum: Plugins
In reply to: [Braintree for WooCommerce Payment Gateway] Braintree WebhookI read this: https://docs.paymentplugins.com/wc-braintree/config/#/webhooks?id=configure-webooks
But can not find Webhook URL (next picture).
https://ibb.co/pPqR08S
- This reply was modified 3 years, 3 months ago by Yordan Milenkov.
WOW, just an
_idaftertransaction– I had to figure it out myself!Now it works fine 🙂
Kind Regards!
Was the order that was place on hold the latest order in your DB at the time of the dispute?
Yes, it returns last order.
What version of WC are you using?
WC Version 6.8.2
WP Version: 6.0.2
WooCommerce provides a transaction property that can be used in the wc_get_orders() function.
That function doesn’t accept a meta_key, meta_value property. It has to be written as a list of arrays.
In my case works fine with
meta_key, meta_value.
If I understand correctly, in the newer version of WCwc_get_orders() functionworks with transaction property. Right?We have a large database and updates are very risky.
Thousands of customers and more than 400,000 subscriptions.Best Regards!
I’m not sure if the above function always returns a correct order.
Isn’t it better to be as follows?
public static function get_wc_order_from_paypal_txn( $id ) { $orders = wc_get_orders( [ 'type' => 'shop_order', 'limit' => 1, 'meta_key' => '_transaction_id', 'meta_value' => $id, 'meta_compare' => '=', ] ); return ! empty( $orders ) ? $orders[0] : null; }Forum: Plugins
In reply to: [Payment Plugins for PayPal WooCommerce] Verification of WebhookHi again,
I create CustomerDisputeCreated.php
And some changes in services.php
But nothing happens, no logs, no errors…
What’s wrong?
/** * Handles the Webhook CUSTOMER.DISPUTE.CREATED * * @package WooCommerce\PayPalCommerce\Webhooks\Handler */ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\Webhooks\Handler; use Psr\Log\LoggerInterface; use WP_REST_Request; use WP_REST_Response; /** * Class CustomerDisputeCreated */ class CustomerDisputeCreated implements RequestHandler { use PrefixTrait; /** * The logger. * * @var LoggerInterface */ private $logger; /** * PaymentCaptureCompleted constructor. * * @param LoggerInterface $logger The logger. */ public function __construct( LoggerInterface $logger ) { $this->logger = $logger; } /** * The event types a handler handles. * * @return string[] */ public function event_types(): array { return array( 'CUSTOMER.DISPUTE.CREATED' ); } /** * Whether a handler is responsible for a given request or not. * * @param \WP_REST_Request $request The request. * * @return bool */ public function responsible_for_request( \WP_REST_Request $request ): bool { return in_array( $request['event_type'], $this->event_types(), true ); } /** * Responsible for handling the request. * * @param WP_REST_Request $request The request. * * @return WP_REST_Response */ public function handle_request( WP_REST_Request $request ): WP_REST_Response { $response = array( 'success' => false ); $order_id = $request['resource'] !== null && isset( $request['resource']['disputed_transactions'][0]['custom'] ) ? $this->sanitize_custom_id( $request['resource']['disputed_transactions'][0]['custom'] ) : 0; if ( ! $order_id ) { $message = sprintf( // translators: %s is the PayPal webhook Id. __( 'No order for webhook event %s was found.', 'woocommerce-paypal-payments' ), $request['id'] !== null && isset( $request['id'] ) ? $request['id'] : '' ); $this->logger->log( 'warning', $message, array( 'request' => $request, ) ); $response['message'] = $message; return new WP_REST_Response( $response ); } $resource = $request['resource']; if ( ! is_array( $resource ) ) { $message = 'Resource data not found in webhook request.'; $this->logger->warning( $message, array( 'request' => $request ) ); $response['message'] = $message; return new WP_REST_Response( $response ); } $wc_order = wc_get_order( $order_id ); if ( ! is_a( $wc_order, \WC_Order::class ) ) { $message = sprintf( 'WC order for PayPal ID %s not found.', $request['resource'] !== null && isset( $request['resource']['id'] ) ? $request['resource']['id'] : '' ); $this->logger->warning( $message ); $response['message'] = $message; return new WP_REST_Response( $response ); } if ( $wc_order->get_status() === 'completed' ) { $wc_order->update_status( 'on-hold', __( 'The order has been held because the customer has opened a dispute in PayPal.' ) ); $subscriptions = wcs_get_subscriptions_for_order( $order_id ); if($subscriptions){ foreach ( $subscriptions as $subscription_id => $subscription ) { $subscription->update_status( 'on-hold', __( 'The subscription has been held because the customer has opened a dispute in PayPal.' ) ); } } } $response['success'] = true; return new WP_REST_Response( $response ); } }Forum: Plugins
In reply to: [WooCommerce PayPal Payments] PayPal dispute callbackI create CustomerDisputeCreated.php
And some changes in services.php
But nothing happens, no logs, no errors…
What’s wrong?
declare(strict_types=1); namespace WooCommerce\PayPalCommerce\Webhooks\Handler; use Psr\Log\LoggerInterface; use WP_REST_Request; use WP_REST_Response; /** * Class PaymentCaptureCompleted */ class CustomerDisputeCreated implements RequestHandler { use PrefixTrait; /** * The logger. * * @var LoggerInterface */ private $logger; /** * PaymentCaptureCompleted constructor. * * @param LoggerInterface $logger The logger. */ public function __construct( LoggerInterface $logger ) { $this->logger = $logger; } /** * The event types a handler handles. * * @return string[] */ public function event_types(): array { return array( 'CUSTOMER.DISPUTE.CREATED' ); } /** * Whether a handler is responsible for a given request or not. * * @param \WP_REST_Request $request The request. * * @return bool */ public function responsible_for_request( \WP_REST_Request $request ): bool { return in_array( $request['event_type'], $this->event_types(), true ); } /** * Responsible for handling the request. * * @param WP_REST_Request $request The request. * * @return WP_REST_Response */ public function handle_request( WP_REST_Request $request ): WP_REST_Response { $response = array( 'success' => false ); $order_id = $request['resource'] !== null && isset( $request['resource']['disputed_transactions'][0]['custom'] ) ? $this->sanitize_custom_id( $request['resource']['disputed_transactions'][0]['custom'] ) : 0; if ( ! $order_id ) { $message = sprintf( // translators: %s is the PayPal webhook Id. __( 'No order for webhook event %s was found.', 'woocommerce-paypal-payments' ), $request['id'] !== null && isset( $request['id'] ) ? $request['id'] : '' ); $this->logger->log( 'warning', $message, array( 'request' => $request, ) ); $response['message'] = $message; return new WP_REST_Response( $response ); } $resource = $request['resource']; if ( ! is_array( $resource ) ) { $message = 'Resource data not found in webhook request.'; $this->logger->warning( $message, array( 'request' => $request ) ); $response['message'] = $message; return new WP_REST_Response( $response ); } $wc_order = wc_get_order( $order_id ); if ( ! is_a( $wc_order, \WC_Order::class ) ) { $message = sprintf( 'WC order for PayPal ID %s not found.', $request['resource'] !== null && isset( $request['resource']['id'] ) ? $request['resource']['id'] : '' ); $this->logger->warning( $message ); $response['message'] = $message; return new WP_REST_Response( $response ); } if ( $wc_order->get_status() === 'completed' ) { $wc_order->update_status( 'on-hold', __( 'The order has been held because the customer has opened a dispute in PayPal.' ) ); $subscriptions = wcs_get_subscriptions_for_order( $order_id ); if($subscriptions){ foreach ( $subscriptions as $subscription_id => $subscription ) { $subscription->update_status( 'on-hold', __( 'The subscription has been held because the customer has opened a dispute in PayPal.' ) ); } } } $response['success'] = true; return new WP_REST_Response( $response ); } }Forum: Plugins
In reply to: [Payment Plugins for PayPal WooCommerce] Verification of WebhookOK,
Thank you!
Kind Regards
Forum: Plugins
In reply to: [Payment Plugins for PayPal WooCommerce] Verification of WebhookI mean actions from PayPal.
If a customer opens a dispute in PayPal – a “on-hold” status should be reflected on the site.
And when we make a refund in PayPal, the order on the site must have become “refunded” status.Regards
Forum: Plugins
In reply to: [Payment Plugins for PayPal WooCommerce] Verification of WebhookHi @mrclayton
We re-create webhook and now “ERROR Webhook failed” is not appear in the log.
But there is no any action on “dispute” and “refund” cases.
We expect Subscription Status “on hold” on “dispute” case and Order Status “Refunded” on “refund” case.
Is that normal?
Kind Regards
Yordan