Dear Developer or supporter,
I have been working on reconfigure the points system in my application, but I’m facing an issue with deducting points correctly. Can you please help me understand why the points deduction is not working as expected?
I guess the reduction of the points are in this method. Could you review the ‘use_user_point_to_rsvp’ method in my code to check if there are any issues with the logic for deducting points when a user RSVPs to an event? in that case I try to deduct 10Points instead of 1. But everthing do it is always 1 Point. No its not true yesterday a came to a point where he added 105 Points instead of deducting 2. But he also messed up all the events I registered to. Anyway in this case he is not messing up the events, but he also doesnt change the amout of point:
public function use_user_point_to_rsvp($user_id, $rsvp_id, $RSVP) {
$required_points = 10; // Anzahl der für die Anmeldung benötigten Punkte
$points = $this->is_user_have_rsvp_points();
$order_id = $points[‘all’][‘orders’][0];
if ($points && $points[‘all’][‘remain’] >= $required_points) {
// Genügend Punkte vorhanden, um sich anzumelden
$points[‘all’][‘remain’] -= $required_points; // Verbleibende Punkte reduzieren
//$points[‘all’][‘used’] += $required_points; // Verwendete Punkte erhöhen
// if using grants
if (strpos($order_id, ‘G’) !== false) {
$granted_points = $this->is_user_grant_points_exists($order_id);
$events_rsvped = isset($granted_points[‘events’]) ? $granted_points[‘events’] : array();
} else {
$events_rsvped = get_post_meta($order_id, ‘_events_rsvped’, true);
}
$val = $RSVP->event_id . ‘-‘ . $RSVP->ri;
// Record rsvp using points
if (empty($events_rsvped)) {
$events_rsvped = array($rsvp_id => $val);
} else {
$events_rsvped[$rsvp_id] = $val;
}
// Record the event featured into the order post
update_post_meta($rsvp_id, ‘_rsvp_using_points’, $order_id);
if (strpos($order_id, ‘G’) !== false) {
$this->set_prop_user_grant_data($order_id, ‘events’, $events_rsvped);
} else {
update_post_meta($order_id, ‘_events_rsvped’, $events_rsvped);
}
// Aktualisiere die Nutzerpunkte
$this->update_post_meta($user_id, $points);
} else {
// Nicht genügend Punkte vorhanden, um sich anzumelden
// Fehlerbehandlung oder Benachrichtigungen hinzufügen
// Zum Beispiel: echo “Nicht genügend Punkte für die Anmeldung.”;
}
}
- Is there something specific I should be looking for in the code that might be causing this problem?
- I have compared the ‘points’ array before and after RSVPing to an event, and it seems that the deduction is not reflected correctly.
- Is it possible that the problem might be related to a specific configuration or setting within the application that affects how points are deducted?
- Can you provide guidance on how to debug or trace the points deduction process in the code to identify where it’s going wrong?
- Are there any potential conflicts or dependencies in the code that might be interfering with the points deduction process?
- Are there any best practices or common pitfalls I should be aware of when handling points in this context?
I really hope you can help me. Please
Best regards Stefan