get cc_type value in magento - php

How could I get the value (text, not the code) of cc_type in my payment gateway model?
In payment gateway model for authorize() and capture() I do get $payment object from which I do get cc_type as $payment->getCcType() but it returns the code for the cc_type how could I get the value of the code. e.g., it return VI for the VISA. So, how could I get VISA from the $payment or $payment->getCcType()?

If you only have the cc code ('VI', 'MA', etc.) at that point you could use:
// $sType = 'VI';
$sType = $payment->getCcType();
$aType = Mage::getSingleton('payment/config')->getCcTypes();
if (isset($aType[$sType])) {
$sName = $aType[$sType];
}
else {
$sName = Mage::helper('payment')->__('N/A');
}
If you already have the Mage_Payment_Model_Info block at that point you could use:
$sName = $payment->getMethod()->getInfoInstance()->getCcTypeName();

Related

Tranzila payment gateway : Not Authorized error message in response

Trying to integrate tranzila payment gateway in my php project and testing with dummy credit card numbers on localhost before go live.I get php code from tranzila official document.
code given below
`
$tranzila_api_host = 'secure5.tranzila.com';
$tranzila_api_path = '/cgi-bin/tranzila71u.cgi';
// Prepare transaction parameters
$query_parameters['supplier'] = 'TERMINAL_NAME'; // 'TERMINAL_NAME' should be replaced by actual terminal name
$query_parameters['sum'] = '45'; // Transaction sum
$query_parameters['currency'] = '1'; // Type of currency 1 NIS, 2 USD, 978 EUR, 826 GBP, 392 JPY
$query_parameters['ccno'] = '12312312'; // Test card number
$query_parameters['expdate']= '0820'; // Card expiry date: mmyy
$query_parameters['myid'] = '12312312'; // ID number if required
$query_parameters['mycvv'] = '123'; // number if required
$query_parameters['cred_type'] = '1'; // This field specifies the type of transaction, 1 - normal transaction, 6 - credit, 8 - payments
// $query_parameters['TranzilaPW'] = 'TranzilaPW' ;
$query_string = '' ;
foreach($query_parameters as $name => $value) {
$query_string .= $name.'='.$value.'&' ;
}
$query_string = substr($query_string , 0 , - 1 ) ; // Remove trailing '&'
// Initiate CURL
$cr = curl_init();
curl_setopt($cr,CURLOPT_URL ,"https://$tranzila_api_host$tranzila_api_path");
curl_setopt($cr,CURLOPT_POST,1);
curl_setopt($cr,CURLOPT_FAILONERROR,true);
curl_setopt($cr,CURLOPT_POSTFIELDS,$query_string) ;
curl_setopt($cr,CURLOPT_RETURNTRANSFER,1);
curl_setopt($cr,CURLOPT_SSL_VERIFYPEER,0);
// Execute request
$result = curl_exec($cr);
$error = curl_error($cr);
if(!empty($error)){
die( $error );
}
curl_close ($cr);
// Preparing associative array with response data
$response_array = explode('&',$result);
$response_assoc = array();
if(count($response_array) > 1){
foreach($response_array as $value){
$tmp = explode('=',$value);
if (count($tmp) > 1 ){
$response_assoc [$tmp[0]] = $tmp[1];
}
}
}
// Analyze the result string
if(!isset($response_assoc['Response'])){
die($result."\n");
/**
* When there is no 'Response' parameter it either means
* that some pre-transaction error happened (like authentication
* problems), in which case the result string will be in HTML format,
* explaining the error, or the request was made for generate token only
* (in this case the response string will only contain 'TranzilaTK'
* parameter)
*/
}else if($response_assoc['Response'] !== '000'){
die($response_assoc['Response']."\n");
// Any other than '000' code means transaction failure
// (bad card, expiry, etc ..)
}else{
die("Success \n");
}
`
Here i replaced supplier with my original supplier name which i can't show here for security reasons.When run this code with actual supplier i got 'Not Authorized' error.

Best approach to process batch API Request Lavel 5

EDIT : Already fixed the error Creating default object from empty value . My question now is just suggestions how to make this process better.
I am making a tool that sends batch API request to a certain URL. I am using https://github.com/stil/curl-easy for batch API request That API will validate the phone numbers I am sending and return a result. That API can support maximum 20 request per second, supposed I have 50,000 API request, what is the best and fastest way to process things?
The current process is, I query to my database for the number of records I have which is the number of phone numbers. Then I make a loop with the number of phone numbers. Inside a single iteration, I will query 13 records from the database then pass it to the queue and process it, when the processing is finished I will query again to the database and update the fields for the the phone number based on the API response. My problem is that I think I have a logic error on my loop when I run this the processing will stop for sometime and gives me:
Creating default object from empty value
I guess that is because of my loop here's my code.
public function getParallelApi()
{
$numItems = DB::connection('mysql')->select("SELECT COUNT(ID) AS cnt FROM phones WHERE status IS NULL");
for($y = 0; $y < $numItems[0]->cnt; $y++)
{
$queue = new \cURL\RequestsQueue;
// Set default options for all requests in queue
$queue->getDefaultOptions()
->set(CURLOPT_TIMEOUT, 5)
->set(CURLOPT_RETURNTRANSFER, true)
->set(CURLOPT_SSL_VERIFYPEER, false);
// This is the function that is called for every completed request
$queue->addListener('complete', function (\cURL\Event $event) {
$response = $event->response;
$json = $response->getContent(); // Returns content of response
$feed = json_decode($json, true);
$phone_number = $feed['msisdn'];
if(isset($phone_number))
{
$status = "";$remarks = "";$network = ""; $country = "";$country_prefix = "";
if(isset($feed['status']))
{
$status = $feed['status'];
}
if(isset($feed['network']))
{
$network = $feed['network'];
}
if(isset($feed['country']))
{
$country = $feed['country'];
}
if(isset($feed['country_prefix']))
{
$country_prefix = $feed['country_prefix'];
}
if(isset($feed['remark']))
{
$remarks = $feed['remark'];
}
$update = Phone::find($phone_number);
$update->network = $network;
$update->country = $country;
$update->country_prefix = $country_prefix;
$update->status = $status;
$update->remarks = $remarks;
$update->save();
}
});
// Get 13 records
$phone = DB::connection('mysql')->select("SELECT * FROM phones WHERE status IS NULL LIMIT 13");
foreach ($phone as $key => $value)
{
$request = new \cURL\Request($this->createCurlUrl($value->msisdn));
// var_dump($this->createCurlUrl($value->msisdn)); exit;
// Add request to queue
$queue->attach($request);
}
// Process the queue
while ($queue->socketPerform()) {
$queue->socketSelect();
}
sleep(2);
$y += 13; // Move to the next 13 records
}
Session::flash('alert-info', 'Data Updated Successfully!');
return Redirect::to('upload');
}
Since the maximum is 20 request per seconds I'm just doing it 13 request per second just to be sure I won't clog their server. I am adding sleep(2); to pause a bit so that I can make sure that the queue is fully processed before moving on.

php - PayPal Express Checkout Item name and number

Why isn't the item name and number not being submitted with the DoExpressCheckout?
Here is what I am sending:
// Single-item purchase
$nvps["METHOD"] = "SetExpressCheckout";
$nvps["RETURNURL"] = "http://www.domain.com/angelpaypal/test/success.php"; // server
$nvps["CANCELURL"] = "http://www.domain.com/angelpaypal/test/fail.php"; // server
$nvps["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
$nvps["PAYMENTREQUEST_0_NOTIFYURL"] = "http://www.domain.com/includes/ipn/paypal/config/ipn-listener.php";
$nvps["PAYMENTREQUEST_0_AMT"] = "$Price";
$nvps["PAYMENTREQUEST_0_CURRENCYCODE"] = "USD";
$nvps["PAYMENTREQUEST_0_ITEMAMT"] = "$Price";
$nvps["L_PAYMENTREQUEST_0_NAME0"] = "$Desc";
$nvps["L_PAYMENTREQUEST_0_NUMBER0"] = "$Item";
$nvps["L_PAYMENTREQUEST_0_AMT0"] = "$Price";
$nvps["L_PAYMENTREQUEST_0_QTY0"] = "1";
$nvps["L_PAYMENTREQUEST_0_ITEMCATEGORY0"] = "Digital"; // specific to Digital Goods
Below is the response:
TOKEN = EC-7RN61912TS2838617
SUCCESSPAGEREDIRECTREQUESTED = false
TIMESTAMP = 2014-03-07T19:16:39Z
CORRELATIONID = b65c4f8669542
ACK = Success
VERSION = 109.0
BUILD = 9917844
INSURANCEOPTIONSELECTED = false
SHIPPINGOPTIONISDEFAULT = false
PAYMENTINFO_0_TRANSACTIONID = 3PF8162359151561E
PAYMENTINFO_0_TRANSACTIONTYPE = expresscheckout
PAYMENTINFO_0_PAYMENTTYPE = instant
PAYMENTINFO_0_ORDERTIME = 2014-03-07T19:16:39Z
PAYMENTINFO_0_AMT = 5.00
PAYMENTINFO_0_FEEAMT = 0.45
PAYMENTINFO_0_TAXAMT = 0.00
PAYMENTINFO_0_CURRENCYCODE = USD
PAYMENTINFO_0_PAYMENTSTATUS = Completed
PAYMENTINFO_0_PENDINGREASON = None
PAYMENTINFO_0_REASONCODE = None
PAYMENTINFO_0_PROTECTIONELIGIBILITY = Ineligible
PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE = None
PAYMENTINFO_0_SECUREMERCHANTACCOUNTID = KEPBS3TF5VPSL
PAYMENTINFO_0_ERRORCODE = 0
PAYMENTINFO_0_ACK = Success
As yuo can see, I am specifying item name and number, although in the response above, I don't see these fields - I want to use them in the IPN (NOTIFYURL) I've added
What you've shown here is SetExpressCheckout. Setting the items here will only make them show up on the PayPal review page during checkout. It will not carry all the way through to the final transaction unless you include those same itemizes details in the DoExpressCheckoutPayment request.
DECP is the end all, be all. Whatever gets sent with that is what ends up in the final PayPal details.

PayPal phone number not shown (using PP php sdk)

We have the following code to transfer our buyer's details to the PayPal:
$ShippingAddr = new AddressType;
// more code ...
$ShippingAddr->Phone = $_userdata['user_phone'];
$BillingAddr = new AddressType;
// more code ...
$BillingAddr->Phone = $_userdata['user_phone'];
$setECReqDetails = new SetExpressCheckoutRequestDetailsType();
// more code ...
$setECReqDetails->Address = $ShippingAddr;
$setECReqDetails->BillingAddress = $BillingAddr;
$setECReqType = new SetExpressCheckoutRequestType();
$setECReqType->Version = '104.0';
$setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
$setECReq = new SetExpressCheckoutReq();
$setECReq->SetExpressCheckoutRequest = $setECReqType;
$setECResponse = $paypalService->SetExpressCheckout($setECReq);
Working fine apart from the phone number which remains empty on PayPal checkout site.
Any idea what we did wrong?
I believe you are trying to get users information as per this webservice. https://developer.paypal.com/docs/api/#get-user-information
So you should call it this way according to the paypal doc,
$_userdata['phone_number'];

DIBS recurring payment, no error message, not working at all

I am using the following code to work, but it is not working
require('DIBSFunctions.php');
//Define input variables (here simply static variables)
$Merchant = "123456";
$OrderID = "AHJ798123AH-BH";
$Currency = "208"; //DKK
$Amount = "30000"; //In smallest possible unit 30000 Øre = DKK 300
$CardNo = "5019100000000000"; //DIBS test Dankort values
$ExpMon = "06"; //DIBS test Dankort value
$ExpYear = "13"; //DIBS test Dankort value
$CVC = "684"; //DIBS test Dankort value
$MD5['K1'] = "~.(S96%u|(UV,~ifxTt.DAKSNb&SKAHD"; //K1 and K2 MUST be gathered through
$MD5['K2'] = "qJuH6vjXHLSDB*%¤&/hbnkjlBHGhjJKJ"; //ones DIBS admin-webinterface.
//Call function DIBSAuth to authorise payment
$RES = DIBSAuth($Merchant,$Amount,$Currency,$CardNo,$ExpMon,$ExpYear,$CVC,$OrderID,$MD5);
echo '<pre>';
print_r($RES);
//Check the response (the DIBS API returns the variable transact on success)
if ( $RES['transact'] != "" )
{
printf ("Authorisation successful! TransaktionID = %s",$RES['transact']);
//Call function DIBSCapt to capture payment
$RES2 = DIBSCapt($Merchant, $Amount, $RES['transact'], $OrderID);
if ( $RES2['status'] == "ACCEPTED" )
{
printf ("Transaction completed");
} else {
printf ("Capture failed!");
}
} else {
printf ("Authorisation failed");
}
This is the code output
Array
(
[reason] => 2
[status] => DECLINED
)
Authorisation failed
require('DIBSFunctions.php');
this file contains the username and password, I am providing it. e.g.
function http_post($host, $path, $data, $auth="") {
$auth['username'] = '123456';
$auth['password'] = '987656656';
//rest of the code
}
if someone wants to see the file 'DIBSFunctions.php' it can be downloadable from here http://tech.dibspayment.com/toolbox/downloads/dibs_php_functions/
i contact to the technical support and got the answer below:
The problem you are experiencing is due to the fact that you are trying to send us real card numbers (test or live). This form of integration requires a PCI certification of your systems.
Most customers use a so called hosted solution, where you use our payment windows. Please refer to tech.dibs.dk for documentation.

Categories