/*******************/
$payment_type = 'Sale';
$amount = $invoice->price + $invoice->due_price + $invoice->service_charge;
$send = 'VERSION=51.0';
$send.= '&USER=' . urlencode('Credit card Username');
$send.= '&PWD=' . urlencode('Credit Card Password');
$send.= '&SIGNATURE=' . urlencode('Credit Card Signature');
$send.= '&METHOD=DoDirectPayment';
$send.= '&PAYMENTACTION=' . $payment_type;
$send.= '&IPADDRESS=' . urlencode($_SERVER['REMOTE_ADDR']);
$send.= '&AMT=' . $amount;
$send.= '&CREDITCARDTYPE=' . $request->cc_type;
$send.= '&ACCT=' . urlencode(str_replace(' ', '', $request->cc_number));
$send.= '&EXPDATE=' . urlencode($request->cc_expire_date_month . $request->cc_expire_date_year);
$send.= '&CVV2=' . urlencode($request->cvv);
$send.= '&FIRSTNAME=' . urlencode('Rupak');
$send.= '&LASTNAME=' . urlencode('s');
$send.= '&EMAIL=' . urlencode('rupak@avainfotech.com');
$send.= '&PHONENUM=' . urlencode('1234567890');
$send.= '&STREET=' . urlencode('Chandigarh');
$send.= '&CITY=' . urlencode('Chandigarh');
$send.= '&STATE=' . urlencode('Panjab');
$send.= '&ZIP=' . urlencode('160047');
$send.= '&COUNTRYCODE=' . urlencode('IND');
$send.= '&CUSTREF=' . (int)$id;
$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, $send);
$response = curl_exec($curl);
curl_close($curl);
if (!$response) {
$json['DoDirectPayment failed'] = curl_error($curl);
}
$response_info = array();
parse_str($response, $response_info);
$json = array();
if (($response_info['ACK'] == 'Success') || ($response_info['ACK'] == 'SuccessWithWarning')) {
// $post = [
// 'cc_number' => $request->cc_number,
// 'transaction_id' => $response_info['TRANSACTIONID'],
// 'payment_status' => $response_info['ACK'],
// 'payment_gateway' => 'Credit card - Paypal',
// 'payment_date' => \Carbon\Carbon::now()->toDateTimeString(),
// 'status' => 1,
// 'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
// ];
$invoice = Invoice::find($id);
$invoice->cc_number = $request->cc_number;
$invoice->transaction_id = $response_info['TRANSACTIONID'];
$invoice->amount_paid = $response_info['AMT'];
$invoice->payment_status = $response_info['ACK'];
$invoice->payment_gateway = 'Credit card - Paypal';
$invoice->payment_date = \Carbon\Carbon::now()->toDateTimeString();
$invoice->status = '1';
$invoice->updated_at = \Carbon\Carbon::now()->toDateTimeString();
if($invoice->save()){
$json['isSuccess'] = 'true';
$json['transaction_id'] = $response_info['TRANSACTIONID'];
}else{
$json['isSuccess'] = 'false';
$json['error'] = 'Unable to update Data';
}
}else{
$json['isSuccess'] = 'false';
$json['error'] = $response_info['L_LONGMESSAGE0'];
}
echo json_encode($json);
exit;
/******************/
$payment_type = 'Sale';
$amount = $invoice->price + $invoice->due_price + $invoice->service_charge;
$send = 'VERSION=51.0';
$send.= '&USER=' . urlencode('Credit card Username');
$send.= '&PWD=' . urlencode('Credit Card Password');
$send.= '&SIGNATURE=' . urlencode('Credit Card Signature');
$send.= '&METHOD=DoDirectPayment';
$send.= '&PAYMENTACTION=' . $payment_type;
$send.= '&IPADDRESS=' . urlencode($_SERVER['REMOTE_ADDR']);
$send.= '&AMT=' . $amount;
$send.= '&CREDITCARDTYPE=' . $request->cc_type;
$send.= '&ACCT=' . urlencode(str_replace(' ', '', $request->cc_number));
$send.= '&EXPDATE=' . urlencode($request->cc_expire_date_month . $request->cc_expire_date_year);
$send.= '&CVV2=' . urlencode($request->cvv);
$send.= '&FIRSTNAME=' . urlencode('Rupak');
$send.= '&LASTNAME=' . urlencode('s');
$send.= '&EMAIL=' . urlencode('rupak@avainfotech.com');
$send.= '&PHONENUM=' . urlencode('1234567890');
$send.= '&STREET=' . urlencode('Chandigarh');
$send.= '&CITY=' . urlencode('Chandigarh');
$send.= '&STATE=' . urlencode('Panjab');
$send.= '&ZIP=' . urlencode('160047');
$send.= '&COUNTRYCODE=' . urlencode('IND');
$send.= '&CUSTREF=' . (int)$id;
$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, $send);
$response = curl_exec($curl);
curl_close($curl);
if (!$response) {
$json['DoDirectPayment failed'] = curl_error($curl);
}
$response_info = array();
parse_str($response, $response_info);
$json = array();
if (($response_info['ACK'] == 'Success') || ($response_info['ACK'] == 'SuccessWithWarning')) {
// $post = [
// 'cc_number' => $request->cc_number,
// 'transaction_id' => $response_info['TRANSACTIONID'],
// 'payment_status' => $response_info['ACK'],
// 'payment_gateway' => 'Credit card - Paypal',
// 'payment_date' => \Carbon\Carbon::now()->toDateTimeString(),
// 'status' => 1,
// 'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
// ];
$invoice = Invoice::find($id);
$invoice->cc_number = $request->cc_number;
$invoice->transaction_id = $response_info['TRANSACTIONID'];
$invoice->amount_paid = $response_info['AMT'];
$invoice->payment_status = $response_info['ACK'];
$invoice->payment_gateway = 'Credit card - Paypal';
$invoice->payment_date = \Carbon\Carbon::now()->toDateTimeString();
$invoice->status = '1';
$invoice->updated_at = \Carbon\Carbon::now()->toDateTimeString();
if($invoice->save()){
$json['isSuccess'] = 'true';
$json['transaction_id'] = $response_info['TRANSACTIONID'];
}else{
$json['isSuccess'] = 'false';
$json['error'] = 'Unable to update Data';
}
}else{
$json['isSuccess'] = 'false';
$json['error'] = $response_info['L_LONGMESSAGE0'];
}
echo json_encode($json);
exit;
/******************/
Comments
Post a Comment