codeigniter - Authorize.Net working process description -
i downloaded library authorize.net , did in controllers:
public function chargecreditcard($amount='20') { $merchantauthentication = new anetapi\merchantauthenticationtype(); $merchantauthentication->setname(login_id); $merchantauthentication->settransactionkey(transaction_key); $refid = 'ref' . time(); $creditcard = new anetapi\creditcardtype(); $creditcard->setcardnumber("4111111111111111"); $creditcard->setexpirationdate("1226"); $creditcard->setcardcode("123"); $paymentone = new anetapi\paymenttype(); $paymentone->setcreditcard($creditcard); // preparing order data transaction $order = new anetapi\ordertype(); $order->setdescription("new item"); //create transaction $transactionrequesttype = new anetapi\transactionrequesttype(); $transactionrequesttype->settransactiontype( "authcapturetransaction"); $transactionrequesttype->setamount($amount); $transactionrequesttype->setorder($order); $transactionrequesttype->setpayment($paymentone); //preparing customer information object $cust = new anetapi\customeraddresstype(); $cust->setfirstname("suzan"); $cust->setlastname("shrestha"); $cust->setaddress("samakhusi,kathmandu"); $cust->setcity("kathmandu"); $cust->setstate("cdr"); $cust->setcountry("nepal"); $cust->setzip("00345"); $cust->setphonenumber("980000000"); $cust->setemail("shresthsujan129@yahoo.com"); $transactionrequesttype->setbillto($cust); $request = new anetapi\createtransactionrequest(); $request->setmerchantauthentication($merchantauthentication); $request->setrefid( $refid); $request->settransactionrequest( $transactionrequesttype); $controller = new anetcontroller\createtransactioncontroller($request); $response = $controller->executewithapiresponse( \net\authorize\api\constants\anetenvironment::sandbox); if ($response != null) { if($response->getmessages()->getresultcode() == 'ok' || $response->getmessages()->getresultcode() == 'error') { $tresponse = $response->gettransactionresponse(); if ($tresponse != null && $tresponse->getmessages() != null) { echo " transaction response code : " . $tresponse->getresponsecode() . "\n"; echo "charge credit card auth code : " . $tresponse->getauthcode() . "\n"; echo "charge credit card trans id : " . $tresponse->gettransid() . "\n"; echo " code : " . $tresponse->getmessages()[0]->getcode() . "\n"; // print_r($tresponse->getmessages()[0]->getcode());exit; echo " description : " . $tresponse->getmessages()[0]->getdescription() . "\n"; } else { echo "transaction failed \n"; if ($tresponse->geterrors() != null) { echo " error code : " . $tresponse->geterrors()[0]->geterrorcode() . "\n"; echo " error message : " . $tresponse->geterrors()[0]->geterrortext() . "\n"; } } } else { echo "transaction failed \n"; $tresponse = $response->gettransactionresponse(); if ($tresponse != null && $tresponse->geterrors() != null) { echo " error code : " . $tresponse->geterrors()[0]->geterrorcode() . "\n"; echo " error message : " . $tresponse->geterrors()[0]->geterrortext() . "\n"; } else { echo " error code : " . $response->getmessages()->getmessage()[0]->getcode() . "\n"; echo " error message : " . $response->getmessages()->getmessage()[0]->gettext() . "\n"; } } } else { echo "no response returned \n"; } }
its working fine. want know is, secure sending information our form authorize.net? or there other way perform operation? can ask user credential fill in authorize.net's site in paypal ? thanks. kind of appreciated.
Comments
Post a Comment