$this->load->model('payment/pp_payflow_iframe');
$this->load->model('sale/order');
$this->load->language('payment/pp_payflow_iframe');
if (isset($this->request->post['order_id']) && isset($this->request->post['amount']) && isset($this->request->post['complete'])) {
$order_id = $this->request->post['order_id'];
$paypal_order = $this->model_payment_pp_payflow_iframe->getOrder($order_id);
$paypal_transactions = $this->model_payment_pp_payflow_iframe->getTransactions($order_id);
$order_info = $this->model_sale_order->getOrder($order_id);
if ($paypal_order && $order_info) {
if ($this->request->post['complete'] == 1) {
$complete = 'Y';
} else {
$complete = 'N';
}
$call_data = array(
'TRXTYPE' => 'D',
'TENDER' => 'C',
'ORIGID' => $paypal_order['transaction_reference'],
'AMT' => $this->request->post['amount'],
'CAPTURECOMPLETE' => $complete,
);
$result = $this->model_payment_pp_payflow_iframe->call($call_data);
if ($result['RESULT'] == 0) {
$data = array(
'order_id' => $order_id,
'type' => 'D',
'transaction_reference' => $result['PNREF'],
'amount' => $this->request->post['amount'],
);
$this->model_payment_pp_payflow_iframe->addTransaction($data);
$this->model_payment_pp_payflow_iframe->updateOrderStatus($order_id, $this->request->post['complete']);
$actions = array();
$actions[] = array(
'title' => $this->language->get('text_capture'),
'href' => $this->url->link('payment/pp_payflow_iframe/refund', 'transaction_reference=' . $result['PNREF'] . '&token=' . $this->session->data['token']),
);
$json['success'] = array(
'transaction_type' => $this->language->get('text_capture'),
'transaction_reference' => $result['PNREF'],
'time' => date('Y-m-d H:i:s'),
'amount' => number_format($this->request->post['amount'], 2),
'actions' => $actions,
);
} else {
$json['error'] = $result['RESPMSG'];
}
} else {
$json['error'] = $this->language->get('error_missing_order');
}
} else {
$json['error'] = $this->language->get('error_missing_data');
}
$this->response->setOutput(json_encode($json));