コード例 #1
0
 /**
  * Process transaction received from payment gateway
  *
  * @since BoxBilling v2.9.15
  *
  * @param Api_Admin $api_admin
  * @param int $id - transaction id to process
  * @param array $ipn - post, get, server, http_raw_post_data
  * @param int $gateway_id - payment gateway id on BoxBilling
  *
  * @return mixed
  * Copy from PayPal Email
  */
 public function processTransaction($api_admin, $id, $data, $gateway_id)
 {
     if (APPLICATION_ENV != 'testing' && !$this->_isIpnValid($data)) {
         throw new Payment_Exception('IPN is not valid');
     }
     $ipn = $data['post'];
     $tx = $api_admin->invoice_transaction_get(array('id' => $id));
     if (!$tx['invoice_id']) {
         $api_admin->invoice_transaction_update(array('id' => $id, 'invoice_id' => $data['get']['bb_invoice_id']));
     }
     if (!$tx['type'] && isset($ipn['txn_type'])) {
         $api_admin->invoice_transaction_update(array('id' => $id, 'type' => $ipn['txn_type']));
     }
     if (!$tx['txn_id'] && isset($ipn['txn_id'])) {
         $api_admin->invoice_transaction_update(array('id' => $id, 'txn_id' => $ipn['txn_id']));
     }
     if (!$tx['txn_status'] && isset($ipn['payment_status'])) {
         $api_admin->invoice_transaction_update(array('id' => $id, 'txn_status' => $ipn['payment_status']));
     }
     if (!$tx['amount'] && isset($ipn['mc_gross'])) {
         $api_admin->invoice_transaction_update(array('id' => $id, 'amount' => $ipn['mc_gross']));
     }
     if (!$tx['currency'] && isset($ipn['mc_currency'])) {
         $api_admin->invoice_transaction_update(array('id' => $id, 'currency' => $ipn['mc_currency']));
     }
     $invoice = $api_admin->invoice_get(array('id' => $data['get']['bb_invoice_id']));
     $client_id = $invoice['client']['id'];
     switch ($ipn['txn_type']) {
         case 'web_accept':
         case 'subscr_payment':
             if ($ipn['payment_status'] == 'Completed') {
                 $bd = array('id' => $client_id, 'amount' => $ipn['mc_gross'], 'description' => 'SkrillMoneybookers transaction ' . $ipn['txn_id'], 'type' => 'SkrillMoneybookers', 'rel_id' => $ipn['txn_id']);
                 if ($this->isIpnDuplicate($ipn)) {
                     throw new Payment_Exception('IPN is duplicate');
                 }
                 $api_admin->client_balance_add_funds($bd);
                 if ($tx['invoice_id']) {
                     $api_admin->invoice_pay_with_credits(array('id' => $tx['invoice_id']));
                 }
                 $api_admin->invoice_batch_pay_with_credits(array('client_id' => $client_id));
             }
             break;
         case 'subscr_signup':
             $sd = array('client_id' => $client_id, 'gateway_id' => $gateway_id, 'currency' => $ipn['mc_currency'], 'sid' => $ipn['subscr_id'], 'status' => 'active', 'period' => str_replace(' ', '', $ipn['period3']), 'amount' => $ipn['amount3'], 'rel_type' => 'invoice', 'rel_id' => $invoice['id']);
             $api_admin->invoice_subscription_create($sd);
             $t = array('id' => $id, 's_id' => $sd['sid'], 's_period' => $sd['period']);
             $api_admin->invoice_transaction_update($t);
             break;
         case 'recurring_payment_suspended_due_to_max_failed_payment':
         case 'subscr_failed':
         case 'subscr_eot':
         case 'subscr_cancel':
             $s = $api_admin->invoice_subscription_get(array('sid' => $ipn['subscr_id']));
             $api_admin->invoice_subscription_update(array('id' => $s['id'], 'status' => 'canceled'));
             break;
         default:
             error_log('Unknown SkrillMoneybookers transaction ' . $id);
             break;
     }
     if (isset($ipn['payment_status']) && $ipn['payment_status'] == 'Refunded') {
         $refd = array('id' => $invoice['id'], 'note' => 'SkrillMoneybookers refund ' . $ipn['parent_txn_id']);
         $api_admin->invoice_refund($refd);
     }
     $d = array('id' => $id, 'error' => '', 'error_code' => '', 'status' => 'processed', 'updated_at' => date('Y-m-d H:i:s'));
     $api_admin->invoice_transaction_update($d);
 }
コード例 #2
0
 /**
  * Process transaction received from payment gateway
  * 
  * 
  * @param Api_Admin $api_admin
  * @param int $id - transaction id to process
  * @param int $gateway_id - payment gateway id on BillingFuse
  * 
  * @return mixed
  */
 public function processTransaction($api_admin, $id, $data, $gateway_id)
 {
     $tx = $api_admin->invoice_transaction_get(array('id' => $id));
     $ipn = array_merge($data['get'], $data['post']);
     if (APPLICATION_ENV != 'testing' && !$this->_isIpnValid($ipn)) {
         throw new Payment_Exception('2Checkout IPN is not valid');
     }
     $api_admin->invoice_transaction_update(array('id' => $id, 'type' => 'ORDER CREATED'));
     $invoice_id = null;
     if (isset($tx['invoice_id'])) {
         $invoice_id = $tx['invoice_id'];
     } elseif (isset($ipn['bf_invoice_id'])) {
         $invoice_id = $ipn['bf_invoice_id'];
         $api_admin->invoice_transaction_update(array('id' => $id, 'invoice_id' => $invoice_id));
     }
     if (!$invoice_id) {
         throw new Payment_Exception('Invoice id could not be determined for this transaction');
     }
     $invoice = $api_admin->invoice_get(array('id' => $invoice_id));
     $client_id = $invoice['client']['id'];
     $tx_data = array('id' => $id, 'status' => 'pending');
     if (empty($tx['txn_id']) && isset($ipn['order_number'])) {
         $tx_data['txn_id'] = $ipn['order_number'];
     }
     if (empty($tx['amount']) && isset($ipn['total'])) {
         $tx_data['amount'] = $ipn['total'];
     }
     if (empty($tx['currency'])) {
         $tx_data['currency'] = $invoice['currency'];
     }
     $api_admin->invoice_transaction_update($tx_data);
     if (isset($ipn['credit_card_processed']) && $ipn['credit_card_processed'] == 'Y') {
         $bd = array('id' => $client_id, 'amount' => $ipn['total'], 'description' => '2Checkout sale id: ' . $ipn['order_number'], 'type' => '2Checkout', 'rel_id' => $ipn['order_number']);
         if ($this->isIpnDuplicate($ipn)) {
             throw new Payment_Exception('IPN is duplicate');
         }
         $api_admin->client_balance_add_funds($bd);
         $tx_data['txn_status'] = 'complete';
         $tx_data['status'] = 'complete';
         $api_admin->invoice_transaction_update($tx_data);
         $api_admin->invoice_batch_pay_with_credits(array('client_id' => $client_id));
     }
     if (isset($ipn['subscription']) && $ipn['subscription'] == 1) {
         $recurrence = '1M';
         if (isset($ipn['li_0_recurrence'])) {
             switch ($ipn['li_0_recurrence']) {
                 case '3 Year':
                     $recurrence = '3Y';
                     break;
                 case '2 Year':
                     $recurrence = '2Y';
                     break;
                 case '1 Year':
                     $recurrence = '1Y';
                     break;
                 case '6 Month':
                     $recurrence = '6M';
                     break;
                 case '3 Month':
                     $recurrence = '3M';
                     break;
                 case '2 Month':
                     $recurrence = '2M';
                     break;
                 case '3 Week':
                     $recurrence = '3W';
                     break;
                 case '2 Week':
                     $recurrence = '2W';
                     break;
                 case '1 Week':
                     $recurrence = '1W';
                     break;
                 case '1 Month':
                 default:
                     $recurrence = '1M';
                     break;
             }
         }
         $sd = array('client_id' => $client_id, 'gateway_id' => $gateway_id, 'currency' => $invoice['currency'], 'sid' => $ipn["order_number"], 'status' => 'active', 'period' => $recurrence, 'amount' => $ipn['total'], 'rel_type' => 'invoice', 'rel_id' => $invoice['id']);
         $api_admin->invoice_subscription_create($sd);
     }
 }