awesomemotive / edd-library

EDD Code Snippet Library
http://library.easydigitaldownloads.com/
141 stars 42 forks source link

I can't use the EDD_Payment class #142

Closed phcaraujo closed 4 years ago

phcaraujo commented 4 years ago

I am integrating my website with hotmart, I am creating a payment manually, however, it is not running.

private function generate_payment($obj){
        $payment = new EDD_Payment();
        $payment->add_download( 3678 ); 
        $payment->email = $obj['email'];
        $payment->status = 'complete'; 
        $payment->save(); 
    }

    private function create_user($obj) {
        $obj['password'] = wp_generate_password(6, false);
        if (email_exists($obj["email"])) {
            $user = get_user_by( 'email', $obj["email"] );
            wp_set_password( $obj['password'], $user->ID );
            generate_payment($obj);         
        } else {
            $userdata = array(
                'user_login' => $obj['email'],
                'user_nicename' => $obj['first_name'],
                'first_name' => $obj['first_name'],
                'last_name' => $obj['last_name'],
                'user_email' => $obj['email'],
                'user_pass' => $obj['password'],
            );
            wp_insert_user($userdata);
            generate_payment($obj);
        }

        $this->send_email($obj);        
    }

Would you help me?

cklosowski commented 4 years ago

@phcaraujo This is not a location for support for custom code. You might need to look into your PHP error logs to see if you are missing any required fields. For instance, this is how our Free Downloads extension creates payments prior to adding items to it:

    $payment = new EDD_Payment;
    $payment->first_name = $user_first;
    $payment->last_name  = $user_last;
    $payment->user_id    = $user ? $user->ID : 0;
    $payment->email      = $email;
    $payment->total      = 0;
    $payment->gateway    = 'manual';
    $payment->status     = 'pending';
phcaraujo commented 4 years ago

@phcaraujo This is not a location for support for custom code. You might need to look into your PHP error logs to see if you are missing any required fields. For instance, this is how our Free Downloads extension creates payments prior to adding items to it:

  $payment = new EDD_Payment;
  $payment->first_name = $user_first;
  $payment->last_name  = $user_last;
  $payment->user_id    = $user ? $user->ID : 0;
  $payment->email      = $email;
  $payment->total      = 0;
  $payment->gateway    = 'manual';
  $payment->status     = 'pending';

There is no PHP error, the function is correct. It is as if I could not use the EDD_Payment class.

I have already sent a support request but have never responded yet.