Export transactions require a customer name and address - Stripe Error - php

I'm using stripe SDK for creating customers & charge to a customer using API, but getting an error with "Fatal error: Uncaught (Status 400) (Request req_ZyqUtykjUcOqrU) As per Indian regulations, export transactions require a customer name and address. More info here: https://stripe.com/docs/india-exports thrown in /opt/lampp/htdocs/stripe/lib/Exception/ApiErrorException.php on line 38"
My code is like below:
\Stripe\Stripe::setApiKey(STRIPE_API_KEY);
$customer = \Stripe\Customer::create(array(
'name' => 'test',
'description' => 'test description',
'email' => $email,
'source' => $token
));
$orderID = strtoupper(str_replace('.','',uniqid('', true)));
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
//'source' => 'rtest',
'amount' => $itemPrice,
'currency' => $currency,
'description' => $itemName,
'metadata' => array(
'order_id' => $orderID
)
));

As your error suggested you need to pass address object in stripe customer create API as per below example
$customer = \Stripe\Customer::create(array(
'name' => 'test',
'description' => 'test description',
'email' => $email,
'source' => $token,
"address" => ["city" => $city, "country" => $country, "line1" => $address, "line2" => "", "postal_code" => $zipCode, "state" => $state]
));
Note: line1 is required in address object

change the currency to INR from USD
i was working on Node & React this helps me
currency: 'INR'
this will fix your problem probably.

Even I was facing the same issue.
Just make sure you are putting the same currency.
For example:
if you have mentioned india as your country then put "inr" else "usd"
use this for your reference:
customer=stripe.Customer.create(
email=request.POST["email"],
name=request.POST["nickname"],
source=request.POST["stripeToken"],
)
customer=stripe.Customer.modify(
customer.id,
address={"city":"mumbai","country":"india","line1":"unr","line2":"thane","postal_code":"421005","state":"maharashtra"},
)
charge=stripe.Charge.create(
customer=customer,
amount=500,
currency='inr',
description="payment"
)

i had this issue in stripe nodejs i fixed it by passing address
const stripeAddress: Stripe.AddressParam = {
line1: userAddress.street1,
line2: userAddress.street2,
city: userAddress.city,
country: userAddress.country,
postal_code: userAddress.zip,
state: userAddress.state,
};
const stripeCustomer: Stripe.Customer = await this.stripe.customers.create(
{
name: userData.name,
description: userData.description,
email: userData.email,
phone: userData.phoneNumber,
address: stripeAddress,
}
);

Here is a complete working solution:
<?php
require('config2.php');
$token = $_POST['stripeToken'];
$customer = \Stripe\Customer::create(array(
'name' => 'test',
'description' => 'test description',
'email' => 'murali#jytra.com',
'source' => $token,
"address" => ["city" => "hyd", "country" => "india", "line1" => "adsafd werew", "postal_code" => "500090", "state" => "telangana"]
));
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => '100',
'currency' => 'inr',
'description' => "TrueCAD 2021 Premium",
));
echo "<pre>";
print_r($charge);
?>

i had this issue with stripe (MERN project). Just make sure you are putting description and shipping details
const paymentIntent = await stripe.paymentIntents.create({
amount: 100, // subunits of currency
currency: "usd",
description: "for amazon-clone project",
shipping: {
name: "Random singh",
address: {
line1: "510 Townsend St",
postal_code: "98140",
city: "San Francisco",
state: "CA",
country: "US",
},
},
});

Related

Issue saving card for customer

I would like to store credit card information for a customer in our QuickBooks account
using the PHP Payments SDK - the following is what I am trying to achieve this but I get an invalid arguments error:
$client = new PaymentClient([
'access_token' => $accessTokenValue,
'environment' => "sandbox" ]);
$array = [
"number" => "4408041234567893",
"expMonth" => "12",
"expYear" => "2026",
"name" => "Test User",
"address" => [
"streetAddress" => "1245 Hana Rd",
"city" => "Richmond",
"region" => "VA",
"country" => "US",
"postalCode" => "44112"
],
"customerid" => "94"
];
$create = CardOperations::createCard($array);
$response = $client->charge($create);
I have not had any luck reaching out to support, any way this can be done, I appreciate the help.
Error received:
Uncaught TypeError: Argument 1 passed to
QuickBooksOnline\Payments\Operations\CardOperations::createCard() must
be an instance of QuickBooksOnline\Payments\Modules\Card, array given
UPDATE using recommended code:
Uncaught ArgumentCountError: Too few arguments to function
QuickBooksOnline\Payments\Operations\CardOperations::createCard(), 1
passed
As per your error it seems the required Card data should be an instance of the class
QuickBooksOnline\Payments\Modules\Card
But you're passing array to it. As per the documentation could you please check this below code , hopefully it will work.
$client = new PaymentClient([
'access_token' => $accessTokenValue,
'environment' => "sandbox"
]);
$cardData = [
"number" => "4408041234567893",
"expMonth" => "12",
"expYear" => "2026",
"name" => "Test User",
"address" => [
"streetAddress" => "1245 Hana Rd",
"city" => "Richmond",
"region" => "VA",
"country" => "US",
"postalCode" => "44112"
],
"customerid" => "94"
];
$chargeData = [
"amount" => "10.55",
"currency" => "USD",
"card" => $cardData,
"context" => [
"mobile" => "false",
"isEcommerce" => "true"
]
];
$customerId = "94";
$charge = ChargeOperations::buildFrom($chargeData);
$chargeResponse = $client->charge($charge);
$clientId = rand();
$card = CardOperations::buildFrom($cardData);
$createCardresponse = $client->createCard($card, $clientId, rand() . "abd");
//or alternatively $createCardresponse = $client->createCard($card, $customerId, rand() . "abd");

How to process a refund with Omnipay - NAB Transact

I am trying to do the refund process and it is connected to the nab test mode server but not processing the refund transaction.
I did a transaction yesterday and wanted to refund the part money but it is not going through and shows the error that Credit card details not available (Error Code 133).
I am sending the request using TransactionID and TransactionReference and the amount to be deducted but not working.
My code:-
public function pay()
{
$gateway = Omnipay::create('NABTransact_SecureXML');
$gateway->setMerchantId('XYZ0010');
$gateway->setTransactionPassword('abcd1234');
$gateway->setTestMode(true);
$card = new CreditCard([
'firstName' => 'ABC',
'lastName' => 'DEF',
'number' => '4444333322221111',
'expiryMonth' => '05',
'expiryYear' => '2025',
'cvv' => '123',
]
);
$transaction = $gateway->purchase([
'amount' => '5000.00',
'currency' => 'AUD',
'transactionId' => '100321', // (My order ID)
'card' => $card,
]
);
$response = $transaction->send();
}
The transactionID i got here is: 706256
please view the screenshot for the above transaction in the NAB:
public function refund()
{
$gateway = Omnipay::create('NABTransact_SecureXML');
$gateway->setMerchantId('XYZ0010');
$gateway->setTransactionPassword('abcd1234');
$gateway->setTestMode(true);
$card = ([
'firstName' => 'ABC',
'lastName' => 'DEF',
'number' => '4444333322221111',
'expiryMonth' => '05',
'expiryYear' => '2025',
'cvv' => '123',
]
);
$refund = $gateway->refund([
'transactionReference' => "706256",
'amount' => "5.00",
'currency' => "AUD",
'transactionId' => "100321",
'messageID' => '4',
'card' => $card,
]);
$refund->send();
}
please view the screenshot for the above transaction in the NAB when
trying to refund:
yes, i had solved it.
this is the sample of my code:
$gateway = Omnipay::create('NABTransact_SecureXML');
gateway->setMerchantId('_ID_');
$gateway->setTransactionPassword('_PASSWORD_');
$gateway->setTestMode(false);
$refund = $gateway->refund([
'transactionReference' => "12345",
'amount' => "500",
'transactionId' => 765897, (hope u must have saved this number in DB)
]);
$response = $refund->send();
$message = $response->getMessage();
if ($response->isSuccessful()) {
return "I m Happy"
} else {
return back()->with('amountError', $message);
}
Let me know how did it go :)

I'm using Stripe API in my code and I have an error : You cannot use a Stripe token more than once: tok_1EIw1gKIAV9zC39qQnFXKzi6

I got an error saying :
Customer cus_EmVoBWWrqnWw4W does not have a linked source with ID tok_1EIw1gKIAV9zC39qQnFXKzi6.
here is my code :
\Stripe\Stripe::setApiKey("sk_test_rUFQ9fpJoK9TlRVJs1nSYd6C");
$user = new User();
$email = $user->getEmail();
//creation du client
$customer = \Stripe\Customer::create(array(
"email" => $email,
));
$charge = \Stripe\Charge::create(array(
"amount" => 2000,
"currency" => "eur",
"source" => $request ->request->get('stripeToken'),
"description" => "Stripe connect - Order 36",
"customer" => $customer->id
));
\Stripe\Stripe::setApiKey("sk_test_rUFQ9fpJoK9TlRVJs1nSYd6C");
$refund = \Stripe\Refund::create([
'charge' => $charge,
'amount' => 1000,
]);
You need to save the card to the customer and then charge the customer. After that, unless the customer has multiple sources and you want to use a specific one, you won't need to pass source to Charge::create.

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!

2Checkout - curl failed error sandbox

<?php
require "lib/Twocheckout.php";
Twocheckout::privateKey('E33E09ED-BD17-4775-AF92-27DE266859A6');
Twocheckout::sellerId('901275831');
Twocheckout::sandbox(true);
try {
$charge = Twocheckout_Charge::auth(array(
"merchantOrderId" => "123",
"token" => $_POST['token'],
"currency" => 'USD',
"total" => '10.00',
"billingAddr" => array(
"name" => 'Joe Flagster',
"addrLine1" => '123 Main Street',
"city" => 'Townsville',
"state" => 'Ohio',
"zipCode" => '43206',
"country" => 'USA',
"email" => 'example#2co.com',
"phoneNumber" => '555-555-5555'
)
));
if ($charge['response']['responseCode'] == 'APPROVED') {
echo "Thanks for your Order!";
echo "<h3>Return Parameters:</h3>";
echo "<pre>";
print_r($charge);
echo "</pre>";
}
} catch (Twocheckout_Error $e) {
print_r($e->getMessage());
}
?>
I am using a test sample data: Sample Test Data
My Seller id: 901275831
What to do now? I am testing it for the first time. but don't know why this error is occurring. Is there anyone can help?
by adding this:
// If you want to turn off SSL verification (Please don't do this in your production environment)
Twocheckout::verifySSL(false); // this is set to true by default
it got working on localhost.

Categories