2Checkout - curl failed error sandbox - php

<?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.

Related

creating stripe connected subscriber account

I'm trying to first create a stripe account, then create the subscription and customer via the created account ID, and then ultimately link the two to create a 'connected' subscriber account on stripe and for it to appear under my connected accounts in my dashboard. So far the script is failing.
// Include Stripe PHP library
require_once 'stripe-php/init.php';
// Set API key
\Stripe\Stripe::setApiKey($STRIPE_API_KEY);
// Create Account
try {
$stripe = \Stripe\Account::create(array(
"email" => $email,
"country" => "US",
"type" => "custom",
'capabilities' => [
'card_payments' => ['requested' => true],
'transfers' => ['requested' => true],
],
));
// Add customer to stripe
try {
$customer = \Stripe\Customer::create(array(
"email" => $email,
"source" => $token
), array("stripe_account" => $stripe->id));
}catch(Exception $e) {
$api_error = $e->getMessage();
}
if(empty($api_error) && $customer){
// Convert price to cents
$priceCents = round($planPrice*100);
// Create a plan
try {
$plan = \Stripe\Plan::create(array(
"product" => [
"name" => $planName
],
"amount" => $priceCents,
"currency" => $currency,
"interval" => $planInterval,
"interval_count" => 1
), array("stripe_account" => $stripe->id));
}catch(Exception $e) {
$api_error = $e->getMessage();
}
if(empty($api_error) && $plan){
// Creates a new subscription
try {
$subscription = \Stripe\Subscription::create(array(
"customer" => $customer->id,
"items" => ["plan" => $plan->id]), array("stripe_account" => $stripe->id));
}catch(Exception $e) {
$api_error = $e->getMessage();
}
echo $api_error;

Error while making payments using Mollie API in php

I am making payments using mollie API in php. But its giving me some errors . I have posted my code and screenshot of the errors.
THIS IS MY CODE:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
try {
require_once "vendor/autoload.php";
$mollie = new \Mollie\Api\MollieApiClient();
$mollie->setApiKey("test_XXXX");
$orderId = time();
$amount = $_POST['amount'];
$payment = $mollie->payments->create([
"amount" => [
"currency" => "EUR",
"value" => "$amount", // You must send the correct number of decimals, thus we enforce the use of strings
],
"description" => "Order #{$orderId}",
"redirectUrl" => "https://example.com/Mollie/return/".$orderId."/",
"webhookUrl" => "https://example.com/Mollie/webhook/",
"metadata" => [
"order_id" => $orderId,
],
]);
print_r($payment);
$payment_data = array(
'payment_id' => $payment->id,
'user_id' => $_POST['user_id'],
'order_id' => $orderId,
'mode' => $payment->mode,
'description' => $payment->description,
'status' => $payment->status,
'added_date' => date('Y-m-d'),
'added_time' => date('H:i:s')
);
print_r($payment_data);
header("Location: " . $payment->getCheckoutUrl(), true, 303);
} catch (\Mollie\Api\Exceptions\ApiException $e) {
echo "API call failed: ". htmlspecialchars($e->getMessage());
}
THE SCREENSHOT:
The first image shows "Uncaught SyntaxError: Unexpected token M in JSON at position 0" in RED color.
The second image is the warning I am getting
First image
Second Image

Export transactions require a customer name and address - Stripe Error

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",
},
},
});

Missing required param: interval - stripe/PHP

I don't understand what going on my stripe code on PHP. I Certainly Definition interval but They are tell me "Missing required param: interval"
I just want to make a plan object.I want to create a plan object after creating a Customer object from the token received from ajax as below.
Is it necessary to obtain another php external resource from Composer etc. to make a plan?
I made a plan as follows
\Stripe\Plan::create();
// \Stripe\Stripe::setApiKey("sk_test_");
$plan = \Stripe\Plan::create(array(
"amount" => 5000,
"interval" => "month",
"product" => array(
"name" => "Emerald classic"
),
"currency" => "jpy",
"id" => "emerald-classic"
));
All sources are this
<?php
header("Content-type: text/plain; charset=UTF-8");
if(isset($_SERVER['HTTP_X_REQUESTED_WITH'])
&& strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{
if (isset($_POST['request']))
{
$name = $_POST['request'];
require_once 'vendor/autoload.php';
\Stripe\Stripe::setApiKey("sk_test_");
\Stripe\Customer::create();
$customer = \Stripe\Customer::create(array(
"description" => "taylor#example.com",
"source" => "$name",
));
//echo $customer;
$customer_array = $customer->__toArray(true);
foreach ($customer_array as $key => $value) {
if ($key === "id") {
$value_cus = $value;
}
}
echo $value_cus;
\Stripe\Plan::create();
// \Stripe\Stripe::setApiKey("sk_test_");
$plan = \Stripe\Plan::create(array(
"amount" => 5000,
"interval" => "month",
"product" => array(
"name" => "Emerald classic"
),
"currency" => "jpy",
"id" => "emerald-classic"
));
};
};
?>

How to do payment using PayFort payment gateway?

I am trying to add a payment using the PayFort payment gateway, but it fails with this error message:
Charge was not processed Request params are invalid.
Please see my code and give any instructions or suggestions for it:
$api_keys = array(
"secret_key" => "test_sec_k_965cd1f7f333f998c907b",
"open_key" => "test_open_k_d6830e5f0f276ebb9046"
);
/* convert 10.00 AED to cents */
$amount_in_cents = 10.00 * 100;
$currency = "AED";
$customer_email = "myMailId#gmail.com";
Start::setApiKey($api_keys["secret_key"]);
try {
$charge = Start_Charge::create(array(
"amount" => $amount_in_cents,
"currency" => $currency,
"card" => '4242424242424242',
"email" => 'myMailId2#gmail.com',
"ip" => $_SERVER["REMOTE_ADDR"],
"description" => "Charge Description"
));
echo "<h1>Successfully charged 10.00 AED</h1>";
echo "<p>Charge ID: ".$charge["id"]."</p>";
echo "<p>Charge State: ".$charge["state"]."</p>";
die;
} catch (Start_Error $e) {
$error_code = $e->getErrorCode();
$error_message = $e->getMessage();
if ($error_code === "card_declined") {
echo "<h1>Charge was declined</h1>";
} else {
echo "<h1>Charge was not processed</h1>";
}
echo "<p>".$error_message."</p>";
die;
}
I found answer
Start::setApiKey($sadad_detail["open_key"]); //Important
$token = Start_Token::create(array(
"number" => $this->input->post("card-number"),
"exp_month" => $this->input->post("expiry-month"),
"exp_year" => $this->input->post("expiry-year"),
"cvc" => $this->input->post("card-cvv"),
"name" => $this->input->post("card-holder-name")
));
//echo "<pre>"; print_r($token); echo '</pre>';
Start::setApiKey($sadad_detail["secret_key"]); //Important
$currency = getCustomConfigItem('currency_code');
$charge = Start_Charge::create(array(
"amount" => (int)200,
"currency" => $currency,
"card" => $token['id'],
"email" => 'test#gmail.com',
"ip" => $_SERVER["REMOTE_ADDR"],
"description" => "Charge Description"
));
Create token first using "open_key" and start charge using "secret_key".
It's work fine. Thanks all.

Categories