function gdlr_lms_paymill_payment() { global $gdlr_lms_option; $ret = array(); if (!empty($_POST['token']) && !empty($_POST['invoice'])) { global $wpdb; $temp_sql = "SELECT * FROM " . $wpdb->prefix . "gdlrpayment "; $temp_sql .= "WHERE id = " . $_POST['invoice']; $result = $wpdb->get_row($temp_sql); $payment_info = unserialize($result->payment_info); $apiKey = $gdlr_lms_option['paymill-private-key']; $request = new Paymill\Request($apiKey); $payment = new Paymill\Models\Request\Payment(); $payment->setToken($_POST['token']); try { $response = $request->create($payment); $paymentId = $response->getId(); $transaction = new Paymill\Models\Request\Transaction(); $transaction->setAmount(floatval($result->pay_amount) * 100)->setCurrency($gdlr_lms_option['paymill-currency-code'])->setPayment($paymentId)->setDescription($payment_info['email']); $response = $request->create($transaction); $wpdb->update($wpdb->prefix . 'gdlrpayment', array('payment_status' => 'paid', 'attachment' => serialize($response), 'payment_date' => date('Y-m-d H:i:s')), array('id' => $_POST['invoice']), array('%s', '%s', '%s'), array('%d')); gdlr_lms_mail($payment_info['email'], __('Stripe Payment Received', 'gdlr-lms'), __('Your verification code is', 'gdlr-lms') . ' ' . $payment_info['code']); $ret['status'] = 'success'; $ret['message'] = __('Payment complete, redirecting to the course page.', 'gdlr-lms'); $ret['redirect'] = get_permalink($result->course_id); $ret['data'] = $result; } catch (PaymillException $e) { $ret['status'] = 'failed'; $ret['message'] = $e->getErrorMessage(); } } else { $ret['status'] = 'failed'; $ret['message'] = __('Failed to retrieve the course, please made the payment from course page again.', 'gdlr-lms'); } die(json_encode($ret)); }
update_option('paypal_debug', $debug_text); curl_close($ch); exit; } curl_close($ch); $debug_text .= 'response: ' . $res . '<br><br>'; update_option('paypal_debug', $debug_text); // inspect IPN validation result and act accordingly if (strcmp($res, "VERIFIED") == 0) { global $wpdb; $wpdb->update($wpdb->prefix . 'gdlrpayment', array('payment_status' => 'paid', 'attachment' => serialize($_POST), 'payment_date' => date('Y-m-d H:i:s')), array('id' => $_POST['invoice']), array('%s', '%s', '%s'), array('%d')); $temp_sql = "SELECT payment_info FROM " . $wpdb->prefix . "gdlrpayment "; $temp_sql .= "WHERE id = " . $_POST['invoice']; $result = $wpdb->get_row($temp_sql); $payment_info = unserialize($result->payment_info); gdlr_lms_mail($payment_info['email'], __('Paypal Payment Received', 'gdlr-lms'), __('Your verification code is', 'gdlr-lms') . ' ' . $payment_info['code']); } } else { if (isset($_GET['paypal_print'])) { print_r(get_option('gdlr_paypal', array())); die; } else { if (isset($_GET['paypal_debug'])) { print_r(get_option('paypal_debug', 'nothing')); die; } else { if (isset($_GET['paypal_clear'])) { delete_option('gdlr_paypal'); echo 'Option Deleted'; die; }
function gdlr_lms_confirm_evidence() { $ret = array(); if (!empty($_POST['value'])) { global $wpdb, $lms_paypal; // remove attachment $current_row = $wpdb->get_row('SELECT attachment FROM ' . $wpdb->prefix . 'gdlrpayment WHERE id=' . $_POST['invoice']); $attachment = unserialize($current_row->attachment); if (!empty($attachment['file']) && file_exists($attachment['file'])) { unlink($attachment['file']); } // update value if ($_POST['value'] == "true") { $wpdb->update($wpdb->prefix . 'gdlrpayment', array('payment_status' => 'paid'), array('id' => $_POST['invoice']), array('%s'), array('%d')); gdlr_lms_mail($_POST['email'], __('Evidence Submission Accept', 'gdlr-lms'), __('Your verification code is', 'gdlr-lms') . ' ' . $_POST['code']); } else { $wpdb->update($wpdb->prefix . 'gdlrpayment', array('payment_status' => 'pending', 'payment_date' => date('Y-m-d')), array('id' => $_POST['invoice']), array('%s', '%s'), array('%d')); gdlr_lms_mail($_POST['email'], __('Evidence Submission Reject', 'gdlr-lms'), __('Please submit the payment evidence again. Thank you.', 'gdlr-lms')); } $ret['status'] = 'success'; } else { $ret['status'] = 'failed'; $ret['message'] = _('Submission Failed, please refresh the page and try again.', 'gdlr-lms'); } die(json_encode($ret)); }
function gdlr_lms_stripe_payment() { global $gdlr_lms_option; $ret = array(); Stripe::setApiKey($gdlr_lms_option['stripe-secret-key']); if (!empty($_POST['token']) && !empty($_POST['invoice'])) { global $wpdb; $temp_sql = "SELECT * FROM " . $wpdb->prefix . "gdlrpayment "; $temp_sql .= "WHERE id = " . $_POST['invoice']; $result = $wpdb->get_row($temp_sql); $payment_info = unserialize($result->payment_info); try { $charge = Stripe_Charge::create(array("amount" => floatval($result->price) * 100, "currency" => $gdlr_lms_option['stripe-currency-code'], "card" => $_POST['token'], "description" => $payment_info['email'])); $wpdb->update($wpdb->prefix . 'gdlrpayment', array('payment_status' => 'paid', 'attachment' => serialize($charge), 'payment_date' => date('Y-m-d H:i:s')), array('id' => $_POST['invoice']), array('%s', '%s', '%s'), array('%d')); gdlr_lms_mail($payment_info['email'], __('Stripe Payment Received', 'gdlr-lms'), __('Your verification code is', 'gdlr-lms') . ' ' . $payment_info['code']); $ret['status'] = 'success'; $ret['message'] = __('Payment complete, redirecting to the course page.', 'gdlr-lms'); $ret['redirect'] = get_permalink($result->course_id); $ret['data'] = $result; } catch (Stripe_CardError $e) { $ret['status'] = 'failed'; $ret['message'] = $e->message; } } else { $ret['status'] = 'failed'; $ret['message'] = __('Failed to retrieve the course, please made the payment from course page again.', 'gdlr-lms'); } die(json_encode($ret)); }