Buna! am si eu nevoie de ajutor cu codul pentru paypal express pe platforma open cart.
Am incercat sa fac un cod in functie de informatiile care le-am gasit in documentatiile lor, si nu numai. Codul este urmatorul:
<?php
class ControllerPaymentPPExpress extends Controller {
protected function index() {
$this->data['button_confirm'] = $this->language->get('button_confirm');
if (!$this->config->get('pp_express')) {
$this->data['action'] = 'https://www.paypal.com/webscr&cmd=_express-checkout&token=';
} else {
$this->data['action'] = 'https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=';
}
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
if (!$this->config->get('pp_express')) {
$api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
} else {
$api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/pp_express.tpl')) {
$this->template = $this->config->get('config_template') . '/template/payment/pp_express.tpl';
} else {
$this->template = 'default/template/payment/pp_express.tpl';
}
$this->render();
}
public function send() {
if (!$this->config->get('pp_express_transaction')) {
$payment_type = 'Authorization';
} else {
$payment_type = 'Sale';
}
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$request = 'METHOD=DoExpressCheckoutPayment';
$request .= '&VERSION=51.0';
$request .= '&USER=' . urlencode($this->config->get('pp_express_username'));
$request .= '&PWD=' . urlencode($this->config->get('pp_express_password'));
$request .= '&SIGNATURE=' . urlencode($this->config->get('pp_express_signature'));
$request .= '&CUSTREF=' . (int)$order_info['order_id'];
$request .= '&PAYMENTACTION=' . $payment_type;
$request .= '&AMT=' . $this->currency->format($order_info['total'], $order_info['currency_code'], false, false);
$request .= '&FIRSTNAME=' . urlencode($order_info['payment_firstname']);
$request .= '&LASTNAME=' . urlencode($order_info['payment_lastname']);
$request .= '&EMAIL=' . urlencode($order_info['email']);
$request .= '&PHONENUM=' . urlencode($order_info['telephone']);
$request .= '&IPADDRESS=' . urlencode($this->request->server['REMOTE_ADDR']);
$request .= '&STREET=' . urlencode($order_info['payment_address_1']);
$request .= '&CITY=' . urlencode($order_info['payment_city']);
$request .= '&STATE=' . urlencode(($order_info['payment_iso_code_2'] != 'US') ? $order_info['payment_zone'] : $order_info['payment_zone_code']);
$request .= '&ZIP=' . urlencode($order_info['payment_postcode']);
$request .= '&COUNTRYCODE=' . urlencode($order_info['payment_iso_code_2']);
$request .= '&CURRENCYCODE=' . urlencode($order_info['currency_code']);
if ($this->cart->hasShipping()) {
$request .= '&SHIPTONAME=' . urlencode($order_info['shipping_firstname'] . ' ' . $order_info['shipping_lastname']);
$request .= '&SHIPTOSTREET=' . urlencode($order_info['shipping_address_1']);
$request .= '&SHIPTOCITY=' . urlencode($order_info['shipping_city']);
$request .= '&SHIPTOSTATE=' . urlencode(($order_info['shipping_iso_code_2'] != 'US') ? $order_info['shipping_zone'] : $order_info['shipping_zone_code']);
$request .= '&SHIPTOCOUNTRYCODE=' . urlencode($order_info['shipping_iso_code_2']);
$request .= '&SHIPTOZIP=' . urlencode($order_info['shipping_postcode']);
} else {
$request .= '&SHIPTONAME=' . urlencode($order_info['payment_firstname'] . ' ' . $order_info['payment_lastname']);
$request .= '&SHIPTOSTREET=' . urlencode($order_info['payment_address_1']);
$request .= '&SHIPTOCITY=' . urlencode($order_info['payment_city']);
$request .= '&SHIPTOSTATE=' . urlencode(($order_info['payment_iso_code_2'] != 'US') ? $order_info['payment_zone'] : $order_info['payment_zone_code']);
$request .= '&SHIPTOCOUNTRYCODE=' . urlencode($order_info['payment_iso_code_2']);
$request .= '&SHIPTOZIP=' . urlencode($order_info['payment_postcode']);
}
if (!$this->config->get('pp_express_test')) {
$curl = curl_init('https://api-3t.paypal.com/nvp');
} else {
$curl = curl_init('https://api-3t.sandbox.paypal.com/nvp');
}
curl_setopt($curl, CURLOPT_PORT, 443);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($curl);
curl_close($curl);
if (!$response) {
$this->log->write('DoExpressCheckoutPayment failed: ' . curl_error($curl) . '(' . curl_errno($curl) . ')');
}
$response_data = array();
parse_str($response, $response_data);
$json = array();
if (($response_data['ACK'] == 'Success') || ($response_data['ACK'] == 'SuccessWithWarning')) {
$this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('config_order_status_id'));
$message = '';
if (isset($response_data['AVSCODE'])) {
$message .= 'AVSCODE: ' . $response_data['AVSCODE'] . "\n";
}
if (isset($response_data['CVV2MATCH'])) {
$message .= 'CVV2MATCH: ' . $response_data['CVV2MATCH'] . "\n";
}
if (isset($response_data['TRANSACTIONID'])) {
$message .= 'TRANSACTIONID: ' . $response_data['TRANSACTIONID'] . "\n";
}
$this->model_checkout_order->update($this->session->data['order_id'], $this->config->get('pp_express_order_status_id'), $message, false);
$json['success'] = $this->url->link('checkout/success');
} else {
$json['error'] = $response_data['L_LONGMESSAGE0'];
}
$this->response->setOutput(json_encode($json));
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/pp_express.tpl')) {
$this->template = $this->config->get('config_template') . '/template/payment/pp_express.tpl';
} else {
$this->template = 'default/template/payment/pp_express.tpl';
}
}
?>
iar codul html + javascript este urmatorul :
<form action="<?php echo $action; ?>" method="post">
<div class="buttons">
<div class="right">
<input type="submit" value="<?php echo $button_confirm; ?>" class="button" />
</div>
</div>
</form>
<script type="text/javascript"><!--
$('#button-confirm').bind('click', function() {
$.ajax({
url: 'index.php?route=payment/pp_express/send',
type: 'post',
data: $('#payment :input'),
dataType: 'json',
beforeSend: function() {
$('#button-confirm').attr('disabled', true);
$('#payment').before('<div class="attention"><img src="catalog/view/theme/default/image/loading.gif" alt="" /> <?php echo $text_wait; ?></div>');
},
success: function(json) {
if (json['error']) {
alert(json['error']);
$('#button-confirm').attr('disabled', false);
}
$('.attention').remove();
if (json['success']) {
location = json['success'];
}
}
});
});
//--></script>
Cunoaste cineva aceasta platforma si ma poate ajuta?
eroare cod paypal express pentru open cart
Moderatori: Zamolxe, Moderatori
eroare cod paypal express pentru open cart
Ultima oară modificat Dum Iul 15, 2012 6:54 pm de către ndianaz, modificat de 2 ori în total.
www.sperantapentruanimalecraiova.com
adoptiianimale.eublog.ro
adoptiianimale.eublog.ro
- vectorialpx
- Senior Member
- Mesaje: 4832
- Membru din: Mar Mar 01, 2005 9:48 am
- Localitate: Bucuresti
- Contact:
Cine este conectat
Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 2 vizitatori