Exemplo n.º 1
0
 private function process_ipn($config, $entry, $status, $transaction_type, $transaction_id, $parent_transaction_id, $subscriber_id, $amount, $pending_reason, $reason, $recurring_amount)
 {
     $this->log_debug(__METHOD__ . "(): Payment status: {$status} - Transaction Type: {$transaction_type} - Transaction ID: {$transaction_id} - Parent Transaction: {$parent_transaction_id} - Subscriber ID: {$subscriber_id} - Amount: {$amount} - Pending reason: {$pending_reason} - Reason: {$reason}");
     $action = array();
     switch (strtolower($transaction_type)) {
         case 'subscr_payment':
             //transaction created
             $action['id'] = $transaction_id;
             $action['transaction_id'] = $transaction_id;
             $action['type'] = 'add_subscription_payment';
             $action['subscription_id'] = $subscriber_id;
             $action['amount'] = $amount;
             $action['entry_id'] = $entry['id'];
             $action['payment_method'] = 'PayPal';
             return $action;
             break;
         case 'subscr_signup':
             //no transaction created
             $action['id'] = $subscriber_id . '_' . $transaction_type;
             $action['type'] = 'create_subscription';
             $action['subscription_id'] = $subscriber_id;
             $action['amount'] = $recurring_amount;
             $action['entry_id'] = $entry['id'];
             $action['ready_to_fulfill'] = !$entry['is_fulfilled'] ? true : false;
             if (!$this->is_valid_initial_payment_amount($entry['id'], $recurring_amount)) {
                 //create note and transaction
                 $this->log_debug(__METHOD__ . '(): Payment amount does not match subscription amount. Subscription will not be activated.');
                 GFPaymentAddOn::add_note($entry['id'], sprintf(__('Payment amount (%s) does not match subscription amount. Subscription will not be activated. Transaction Id: %s', 'gravityformspaypal'), GFCommon::to_money($recurring_amount, $entry['currency']), $subscriber_id));
                 GFPaymentAddOn::insert_transaction($entry['id'], 'payment', $subscriber_id, $recurring_amount);
                 $action['abort_callback'] = true;
             }
             return $action;
             break;
         case 'subscr_cancel':
             //no transaction created
             $action['id'] = $subscriber_id . '_' . $transaction_type;
             $action['type'] = 'cancel_subscription';
             $action['subscription_id'] = $subscriber_id;
             $action['entry_id'] = $entry['id'];
             return $action;
             break;
         case 'subscr_eot':
             //no transaction created
             if (empty($transaction_id)) {
                 $action['id'] = $subscriber_id . '_' . $transaction_type;
             } else {
                 $action['id'] = $transaction_id;
             }
             $action['type'] = 'expire_subscription';
             $action['subscription_id'] = $subscriber_id;
             $action['entry_id'] = $entry['id'];
             return $action;
             break;
         case 'subscr_failed':
             //no transaction created
             if (empty($transaction_id)) {
                 $action['id'] = $subscriber_id . '_' . $transaction_type;
             } else {
                 $action['id'] = $transaction_id;
             }
             $action['type'] = 'fail_subscription_payment';
             $action['subscription_id'] = $subscriber_id;
             $action['entry_id'] = $entry['id'];
             $action['amount'] = $amount;
             return $action;
             break;
         default:
             //handles products and donation
             switch (strtolower($status)) {
                 case 'completed':
                     //creates transaction
                     $action['id'] = $transaction_id . '_' . $status;
                     $action['type'] = 'complete_payment';
                     $action['transaction_id'] = $transaction_id;
                     $action['amount'] = $amount;
                     $action['entry_id'] = $entry['id'];
                     $action['payment_date'] = gmdate('y-m-d H:i:s');
                     $action['payment_method'] = 'PayPal';
                     $action['ready_to_fulfill'] = !$entry['is_fulfilled'] ? true : false;
                     if (!$this->is_valid_initial_payment_amount($entry['id'], $amount)) {
                         //create note and transaction
                         $this->log_debug(__METHOD__ . '(): Payment amount does not match product price. Entry will not be marked as Approved.');
                         GFPaymentAddOn::add_note($entry['id'], sprintf(__('Payment amount (%s) does not match product price. Entry will not be marked as Approved. Transaction Id: %s', 'gravityformspaypal'), GFCommon::to_money($amount, $entry['currency']), $transaction_id));
                         GFPaymentAddOn::insert_transaction($entry['id'], 'payment', $transaction_id, $amount);
                         $action['abort_callback'] = true;
                     }
                     return $action;
                     break;
                 case 'reversed':
                     //creates transaction
                     $this->log_debug(__METHOD__ . '(): Processing reversal.');
                     GFAPI::update_entry_property($entry['id'], 'payment_status', 'Refunded');
                     GFPaymentAddOn::add_note($entry['id'], sprintf(__('Payment has been reversed. Transaction Id: %s. Reason: %s', 'gravityformspaypal'), $transaction_id, $this->get_reason($reason)));
                     GFPaymentAddOn::insert_transaction($entry['id'], 'refund', $action['transaction_id'], $action['amount']);
                     break;
                 case 'canceled_reversal':
                     //creates transaction
                     $this->log_debug(__METHOD__ . '(): Processing a reversal cancellation');
                     GFAPI::update_entry_property($entry['id'], 'payment_status', 'Paid');
                     GFPaymentAddOn::add_note($entry['id'], sprintf(__('Payment reversal has been canceled and the funds have been transferred to your account. Transaction Id: %s', 'gravityformspaypal'), $entry['transaction_id']));
                     GFPaymentAddOn::insert_transaction($entry['id'], 'payment', $action['transaction_id'], $action['amount']);
                     break;
                 case 'processed':
                 case 'pending':
                     $action['id'] = $transaction_id . '_' . $status;
                     $action['type'] = 'add_pending_payment';
                     $action['transaction_id'] = $transaction_id;
                     $action['entry_id'] = $entry['id'];
                     $action['amount'] = $amount;
                     $action['entry_id'] = $entry['id'];
                     $amount_formatted = GFCommon::to_money($action['amount'], $entry['currency']);
                     $action['note'] = sprintf(__('Payment is pending. Amount: %s. Transaction Id: %s. Reason: %s', 'gravityformspaypal'), $amount_formatted, $action['transaction_id'], $this->get_pending_reason($pending_reason));
                     return $action;
                     break;
                 case 'refunded':
                     $action['id'] = $transaction_id . '_' . $status;
                     $action['type'] = 'refund_payment';
                     $action['transaction_id'] = $transaction_id;
                     $action['entry_id'] = $entry['id'];
                     $action['amount'] = $amount;
                     return $action;
                     break;
                 case 'voided':
                     $action['id'] = $transaction_id . '_' . $status;
                     $action['type'] = 'void_authorization';
                     $action['transaction_id'] = $transaction_id;
                     $action['entry_id'] = $entry['id'];
                     $action['amount'] = $amount;
                     return $action;
                     break;
                 case 'denied':
                 case 'failed':
                     $action['id'] = $transaction_id . '_' . $status;
                     $action['type'] = 'fail_payment';
                     $action['transaction_id'] = $transaction_id;
                     $action['entry_id'] = $entry['id'];
                     $action['amount'] = $amount;
                     return $action;
                     break;
             }
             break;
     }
 }