Update CC info of Braintree in PHP - php

I am trying to update CC info of braintree but function provided in docs is not working . and I am unable to find out the reason.
Here is my function :
public function updateCC(){
$fname = $this->input->get_post('fname');
$lname = $this->input->get_post('lname');
$expirationYear = $this->input->get_post('expirationYear');
$expirationMonth = $this->input->get_post('expirationMonth');
$cardholderName = $this->input->get_post('cardholderName');
$cvv = $this->input->get_post('cvv');
$cc_no = $this->input->get_post('cc_no');
$token = $this->input->get_post('token');
$BTCustomerID = $this->input->get_post('BTCustomerID ');
$result = Braintree_Customer::update(
$BTCustomerID,
(
'firstName' => $fname,
'lastName' => $lname,
'creditCard' => (
'paymentMethodNonce' => 'fake-valid-nonce',
'options' => (
'updateExistingToken' => $token,
'verifyCard' => true
)
)
));
echo json_encode(array('error'=>-1));
}
Due to this code my application is crashing .
$result = Braintree_Customer::update(
$BTCustomerID,
(
'firstName' => $fname,
'lastName' => $lname,
'creditCard' => (
'paymentMethodNonce' => 'fake-valid-nonce',
'options' => (
'updateExistingToken' => $token,
'verifyCard' => true,
)
)
));

I’m a developer at Braintree. In your call to Braintree_Customer::update(), paymentMethodNonce must be passed inside of creditCard at the same level as options. In your code you are passing the it inside of options. See this code example for reference.

Related

Can't get an unenrolled 3d-secure card authenticaited (secrure trading)

I am running a PHP 7.3, running on apache server. I used composer to get this library:
https://github.com/SecureTrading/PHP-API
For the code provided, I am now using the test site reference. I already managed to use for regular transitions. I now started managing 3D secure transactions, with the test MAESTRO card provided by secure trading here: https://docs.securetrading.com/document/testing/. the one designed not to demand 3D auth - that is 5000000000000421
The code provided next, will sum up the way I think thought this should work: I start by creating AUTH request, get error 30004, using CACHETOKENISE request to get a token, run THREEDQUERY to figure out if I need a full auth sceme on this card, get N as an answer, and run another AUTH request, this time with the transactionreference.
I am providing a version of the code I am testing (obviously, username, password and site reference name was removed to protect my privacy, but the code otherwise is the same)
<?php
$configData = array(
'username' => 'api#gigsberg.com',
'password' => 'xq!Kq$j4',
);
$site_refrance = 'test_gigsberg74319';
?>
<?php
$configData = array(
'username' => '*****',
'password' => '*****',
);
$site_refrance = '*****';
if (!($autoload = realpath(__DIR__ . '/vendor/autoload.php'))) {
throw new \Exception('Composer autoloader file could not be found.');
}
require_once($autoload);
$api = \Securetrading\api($configData);
$requestData = array(
'sitereference' => $site_refrance,
'requesttypedescription' => 'AUTH',
'accounttypedescription' => 'ECOM',
'currencyiso3a' => 'GBP',
'mainamount' => '1000',
'pan' => '5000000000000421',
'expirymonth' => '12',
'expiryyear' => '2030',
'securitycode' => '123',
);
echo '<pre>';
print_r($requestData);
$response = $api->process($requestData)->toArray();
print_r( $response['responses'] ); // $response['responses'][0]['errorcode'] == 30004
echo "\n--------------------------------------\n";
$transactionreference = $response['responses'][0]['transactionreference'];
$requestData = array(
'sitereference' => $site_refrance,
'expirymonth' => '12',
'expiryyear' => '2030',
'requesttypedescriptions' => array('CACHETOKENISE'),
'securitycode' => '123',
'orderreference' => $transactionreference,
'pan' => '5000000000000421'
);
print_r($requestData);
$response = $api->process($requestData)->toArray();
echo "\n--------------------------------------\n";
$cachetoken = $response['responses'][0]['cachetoken'];
$requestData = array(
'termurl' => 'https://termurl.com',
'accept' => 'text/html,*/*',
'currencyiso3a' => 'GBP',
'requesttypedescription' => 'THREEDQUERY',
'accounttypedescription' => 'ECOM',
'sitereference' => $site_refrance,
'baseamount' => '1000',
'pan' => '5000000000000421',
'expirymonth' => '12',
'expiryyear' => '2030',
'cachetoken' => $cachetoken,
);
print_r($requestData);
$response = $api->process($requestData)->toArray(); // $response['responses'][0]['enrolled'] == 'N'
/* Copying from the docs here: https://docs.securetrading.com/document/api/security/3-d-secure/
* If the enrolled value returned in the response is “Y”, the customer’s card is enrolled in 3-D secure. Please refer to the following table for enrolled values:
* .
* .
* N - The card is not enrolled in the card issuer’s 3-D Secure scheme. - Perform an AUTH Request, including the transactionreference returned in the THREEDQUERY response.
* .
* .
*/
print_r( $response['responses'] );
echo "\n--------------------------------------\n";
$transactionreference = $response['responses'][0]['transactionreference'];
$requestData = array(
'sitereference' => $site_refrance,
'requesttypedescription' => 'AUTH',
'accounttypedescription' => 'ECOM',
'currencyiso3a' => 'GBP',
'mainamount' => '1000',
'pan' => '5000000000000421',
'expirymonth' => '12',
'expiryyear' => '2030',
'securitycode' => '123',
'transactionreference' => $transactionreference
);
print_r($requestData);
$response = $api->process($requestData)->toArray();
print_r( $response['responses'] ); // Still get $response['responses'][0]['errorcode'] == 30004
I expected it to give me a note that all works well, but I still got error 30004, as if the transactionreference wasn't provided. Any idea what I can do, to fix this code, and prevent this error?
Thanks in advance
Yair
Well, I read the Api tests, and I found my error. On the last request data, instead of
$requestData = array(
.
.
'transactionreference' => $transactionreference
.
.
);
I should use
$requestData = array(
.
.
'parenttransactionreference' => $transactionreference
.
.
);
Anyway, home this helps somone

Getting the rate of a specific service - EasyPost

I currently have EasyPost creating a shipment. When I create the shipment it provides me with all the available services and rates.
I would like to dynamically select service and only return that rate.
I originally would read through the array using the index number (I guess that how to describe it).
The problem with this is every time I create a new shipment the order of the rates array changes so what would have been $shipment->rates[0]['rate'] would be express and then the next time first class.
I want to create a shipment with "Express" and only return that rate.
Any advice would be appreciated.
Here is my code:
$name = $this->thiscustomer->cust_first . ' ' . $this->thiscustomer->cust_first;
$street_1 = $this->thiscustomer->street_1;
$street_2 = $this->thiscustomer->street_2;
$city = $this->thiscustomer->city;
$state = $this->thiscustomer->state;
$zip = $this->thiscustomer->zip;
$weight = $this->weight;
$packaging = $this->packaging;
$service = $this->service;
$caddress = $this->consultant->address;
$cstreet_1 = $this->consultant->street_1;
$cstreet_2 = $this->consultant->street_2;
$ccity = $this->consultant->city;
$cstate = $this->consultant->state;
$czip = $this->consultant->zip;
$cname = $this->consultant->first_name . ' ' . $this->consultant->last_name;
$cuser_id = $this->consultant->user_id;
require_once(dirname(__FILE__) . '/lib/easypost.php');
\EasyPost\EasyPost::setApiKey('KUk4fZUI6YaYc1h0FiIXFw');
$shipment = \EasyPost\Shipment::create(array(
'to_address' => array(
"name" => $name,
"street1" => $street_1,
"street2" => $street_2,
"city" => $city,
"state" => $state,
"zip" => $zip
),
'from_address' => array(
"company" => $cname,
"street1" => $cstreet_1,
"street2" => $cstreet_2,
"city" => $ccity,
"state" => $cstate,
"zip" => $czip
),
'parcel' => array(
'weight' => $weight,
'predefined_package'=> $packaging
),
'rates' => array(
'service' => $service
)
));
echo $shipment->rates[0]['rate']. '<br>';
In EasyPost's Getting Started Guide there is an example of buying a specific carrier+rate:
$shipment->buy($shipment->lowest_rate(array('USPS'), array('Express')));
you can get different rates through below lines of code
if(!empty($shipment->rates))
{
$count = 0;
foreach($shipment->rates as $rate)
{
$serviceRates[$count] = [
'service' => $rate->service,
'carrier' => $rate->carrier,
'rate' => $rate->rate,
'currency' => $rate->currency,
'delivery_days' => $rate->delivery_days
];
$count++;
}
}
else
{
echo 'no result fond for given address';
}
print_r($serviceRates);
#KFunk is correct that EasyPost does not provide a native way to accomplish what you are asking since this use case is unique to you. The EasyPost client libraries provide all the functions needed to interact with the API; however, all of the business logic is left to the user.
If you want to create a shipment but only show a single rate to the user, you will need to filter out the other rates in your own application. To do this, you can follow the simple example here:
<?php
\EasyPost\EasyPost::setApiKey($_ENV['EASYPOST_API_KEY']);
// Create your shipment, the response will contain all rates for all configured carriers
$shipment = \EasyPost\Shipment::create([
'to_address' => [
'name' => 'Dr. Steve Brule',
'street1' => '179 N Harbor Dr',
'city' => 'Redondo Beach',
'state' => 'CA',
'zip' => '90277',
'country' => 'US',
'phone' => '3331114444',
'email' => 'dr_steve_brule#gmail.com'
],
'from_address' => [
'name' => 'EasyPost',
'street1' => '417 Montgomery Street',
'street2' => '5th Floor',
'city' => 'San Francisco',
'state' => 'CA',
'zip' => '94104',
'country' => 'US',
'phone' => '3331114444',
'email' => 'support#easypost.com'
],
'parcel' => [
'length' => 20.2,
'width' => 10.9,
'height' => 5,
'weight' => 65.9
]
]);
$rates = $shipments->rates;
// Filter out all the rates that aren't the desired one, in this case - `Express`
$expressRate = null;
foreach ($rates as $rate) {
if ($rate->service == "Express") {
$expressRate = $rate;
break;
}
}
// Return $expressRate to your UI or do with it what you need
echo $expressRate;
Relying on array ordering is an antipattern that should be avoided. Array indices are never guaranteed to remain in the same order and do not have a strong bond to the data in question.
For further help with the EasyPost API specifically, you can reach out to our support team via support#easypost.com. Best of luck!

How to get the paypal customerid(subscriber_id)

I am using cakephp2.0 framework. I am doing recurring payment. I am not getting the customer_id and other variables. And I also send the Recurring to Y.
Here is my code:
$paypalParams = array(
'paymentAction' => "Sale",
'amount' => $_POST['amount'],
'currencyCode' => "USD",
'creditCardType' => $_POST['card_type'],
'creditCardNumber' => trim(str_replace(" ","",$_POST['card_number'])),
'expMonth' => $_POST['expiry_month'],
'expYear' => $_POST['expiry_year'],
'cvv' => $_POST['cvv'],
'firstName' => $firstName,
'lastName' => $lastName,
'city' => $city,
'zip' => $zipcode,
'countryCode' => $countryCode,
'recurring' => 'Y',
'billingPeriod' => $session_details['paymentType'],
'billingFrequency' => "1",
'totalBillingCycles' => "0",
);
echo "<pre>"; print_r($paypalParams);
$response = $paypal->paypalCall($paypalParams);
When I call paypalCall function:
public function paypalCall($params){
/*
* Construct the request string that will be sent to PayPal.
* The variable $nvpstr contains all the variables and is a
* name value pair string with & as a delimiter
*/
$recurringStr = (array_key_exists("recurring",$params) && $params['recurring'] == 'Y')?'&RECURRING=Y':'';
$nvpstr = "&TOTALBILLINGCYCLES=".$params['totalBillingCycles']."&BILLINGFREQUENCY=".$params['billingFrequency']."&BILLINGPERIOD=".$params['billingPeriod']."&PAYMENTACTION=".$params['paymentAction']."&AMT=".$params['amount']."&CREDITCARDTYPE=".$params['creditCardType']."&ACCT=".$params['creditCardNumber']."&EXPDATE=".$params['expMonth'].$params['expYear']."&CVV2=".$params['cvv']."&FIRSTNAME=".$params['firstName']."&LASTNAME=".$params['lastName']."&CITY=".$params['city']."&ZIP=".$params['zip']."&COUNTRYCODE=".$params['countryCode']."&CURRENCYCODE=".$params['currencyCode'].$recurringStr;
//echo "<pre>"; print_r($nvpstr); die;
/* Make the API call to PayPal, using API signature.
The API response is stored in an associative array called $resArray */
$resArray = $this->hashCall("DoDirectPayment",$nvpstr);
echo "<pre>"; print_r($resArray); die;
return $resArray;
}
When I print this array($resArray) it gives only these parameters:
enter code here
<pre>Array
(
[TIMESTAMP] => 2016-12-29T09:05:26Z
[CORRELATIONID] => 42743fa743c6
[ACK] => Success
[VERSION] => 65.1
[BUILD] => 24616352
[AMT] => 19.99
[CURRENCYCODE] => USD
[AVSCODE] => X
[CVV2MATCH] => M
[TRANSACTIONID] => 9A3464215B244930U
)
There is no customerid(subscriber_id).
Could anyone help me to see what I am doing wrong?

Unable to get session data from paypal express checkout in laravel 4

I am unable to get session information in omnipay laravel 4 after getting express checkout return after making express checkout.
I do get Tokens and PayerID noting else. Session data of that site become empty.
Please tell how can I completePurchase Process. Is there any way to get purchase order ID from paypal. I am using omnipay.
public function doSaveAndProcessedToPayPal( $purchaseOrder)
{
$purchaseOrderId = $purchaseOrder->id;
Session::put('currentUserEmail', $email);
Session::put('purchaseOrderId', $purchaseOrderId);
Session::put('amount', $amount);
$gateway = $this->getPayPalGateway();
$items = new Omnipay\Common\ItemBag();
$items->add(array(
'name' => $productName,
'quantity' => '1',
'price' => (float)$amount,
));
$response = $gateway->purchase(
array(
'cancelUrl' => CANCEL_URL,
'returnUrl' => RETURN_URL,
'amount' => (float)$amount,
'currency' => $currency
)
)->setItems($items)->send();
$response->redirect();
}
public function doPerformPostPaymentOperation()
{
$gateway = $this->getPayPalGateway();
$purchaseOrderId = Session::get('purchaseOrderId');
$amount = Session::get('amount');
$currency = Session::get('currency');
$data = Session::all();
echo "<pre>";
print_r( $data );
echo "</pre>";
echo $purchaseOrderId;
die();
$response = $gateway->completePurchase(array(
'transactionId' => "ORD-".$purchaseOrderId,
'transactionReference' => "REF-".$purchaseOrderId,
'amount' => (float)$amount,
'currency' => $currency,
))->send();
if ( ! $response->isSuccessful())
{
throw new Exception($response->getMessage());
}
}
Output
Array
(
[_token] => lnvG1S3eU2JsHJSciOTjixEEHiSwZVX47daRLDXE
[flash] => Array
(
[old] => Array
(
)
[new] => Array
(
)
)
)

Create a customer address to already exist customer - Magento

I'm trying create programmatically a new address to customers that was imported a some time ago for me.
My Code:
//All variables about customer address info are filled
$customerModel = Mage::getModel('customer/customer');
$customer = $customerModel->setWebsiteId(1)->loadByEmail($_email);
if($customer->getId()) {
$addressData = array (
'firstname' => $customer->getFirstname(),
'lastname' => $customer->getLastname(),
'street' => "$_s1
$_s2
$_s3
$_s4",
'city' => $_city,
'country_id' => 'BR',
'region_id' => $_regionid,
'postcode' => $_cep,
'telephone' => $_tel,
'celular' => $_cel,
'is_default_billing' => 1,
'is_default_shipping' => 1
);
$address = Mage::getModel('customer/address');
$address->addData($addressData);
$customer->addAddress($address);
try {
print_r($addressData);
$customer->save();
}
catch (Exception $e) {
}
}
Object loaded '$customer' isnt what I need: a full customer object.
Any Idea?
You have to save customer address in different way, following is address saving code.
$customerAddress = Mage::getModel('customer/address');
$customerAddress->setData($addressData)
->setCustomerId($customer->getId())
->setSaveInAddressBook('1');
$customerAddress->save();
The full code will look like:
$customerModel = Mage::getModel('customer/customer');
$customer = $customerModel->setWebsiteId(1)->loadByEmail($_email);
if($customer->getId()) {
$addressData = array (
'firstname' => $customer->getFirstname(),
'lastname' => $customer->getLastname(),
'street' => "$_s1
$_s2
$_s3
$_s4",
'city' => $_city,
'country_id' => 'BR',
'region_id' => $_regionid,
'postcode' => $_cep,
'telephone' => $_tel,
'celular' => $_cel,
'is_default_billing' => 1,
'is_default_shipping' => 1
);
$customerAddress = Mage::getModel('customer/address');
$customerAddress->setData($addressData)
->setCustomerId($customer->getId())
->setSaveInAddressBook('1');
$customerAddress->save();
//And reload customer object
$customer = Mage::getModel('customer/customer')->load($customer->getId());
//Check customer data
print_r($customer->getData());
//Check addresses
foreach($customer->getAddresses() as $address)
{
print_r($address);
}
}

Categories