How to do payment using PayFort payment gateway? - php

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.

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;

instamojo how to pass custom fields inphp

i am trying to integrate instamojo payment gateway on my website
$product_name = "Buy Wine";
$price = $sub_total;
$name = $_POST['f_name'].' '.$_POST['l_name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
include 'src/instamojo.php';
$api = new Instamojo\Instamojo('api_key', 'auth_token','https://test.instamojo.com/api/1.1/');
try {
$response = $api->paymentRequestCreate(array(
"purpose" => $product_name,
"amount" => $price,
"buyer_name" => $name,
"phone" => $phone,
"send_email" => true,
"send_sms" => true,
"email" => $email,
'allow_repeated_payments' => false,
"redirect_url" => "http://trezeefoods.com/thankyou.php",
"webhook" => "http://trezeefoods.com/webhook.php"
));
//print_r($response);
$pay_ulr = $response['longurl'];
//Redirect($response['longurl'],302); //Go to Payment page
header("Location: $pay_ulr");
exit();
}
catch (Exception $e) {
print('Error: ' . $e->getMessage());
}
here i trying to pass product id on success page in response like
"order_id" => 1234,
but i can't receive this on success page

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

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.

How to generate token in stripe payment gateway

I want to make a payment gateway using Stripe. Here is my code. The config file and first of all i add a stripe library in confiig file. I want a token from this. How do I make or generate a token from stripe?
<?php
require_once('./lib/Stripe.php');
$stripe = array(
secret_key => 'sk_test_SrG9Yb8SrhcDNkqsGdc5eKu1',
publishable_key => 'pk_test_8ZBVXSwrHDKuQe6dgMNfk8Wl'
);
Stripe::setApiKey($stripe['secret_key']);
?>
<?php require_once('config.php'); ?>
<form action="charge.php" method="post">
<script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"
data-key="<?php echo $stripe['publishable_key']; ?>"
data-amount="5000" data-description="One year's subscription"></script>
</form>
<?php require_once('config.php'); ?>
<form action="charge.php" method="post">
<script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"
data-key="<?php echo $stripe['publishable_key']; ?>"
data-amount="5000" data-description="One year's subscription"></script>
</form>
require_once('../lib/Stripe.php');
Stripe::setApiKey("sk_test_SrG9Yb8SrhcDNkqsGdc5eKu1");
$result = Stripe_Token::create(
array(
"card" => array(
"name" => $user['name'],
"number" => base64decrypt($user['card_number']),
"exp_month" => $user['month'],
"exp_year" => $user['year'],
"cvc" => base64decrypt($user['cvc_number'])
)
)
);
$token = $result['id'];
$charge = Stripe_Charge::create(array(
"amount" => $data_input['amount']*100,
"currency" => "usd",
"card" => $token,
"description" => "Charge for test#example.com"
));
I found this code snippet on their API Documentation.
You should try to put this code on your charge.php
// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://dashboard.stripe.com/account
Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = Stripe_Charge::create(array(
"amount" => 1000, // amount in cents, again
"currency" => "usd",
"card" => $token,
"description" => "payinguser#example.com")
);
} catch(Stripe_CardError $e) {
// The card has been declined
}
Let me know if you still have the problem to grab this token
Updated for stripe 3.12.0
namespace Stripe;
require_once('stripe-php-3.12.0/vendor/autoload.php');
require_once('stripe-php-3.12.0/lib/Stripe.php');
Stripe::setApiKey("yourAPIKey");
// Get the credit card details submitted by the form
$status;
if(isset($_POST['amount'])
{
$amount = $_POST['amount'] * 100;
$token = Token::create(
array(
"card" => array(
"name" => $user['name'],
"number" => $user['card_number'],
"exp_month" => $user['month'],
"exp_year" => $user['year'],
"cvc" => $user['cvc_number']
)
)
);
// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = Charge::create(array(
"amount" => $amount , // amount in cents, again
"currency" => "usd",
"source" => $token,
"description" => "Example charge"
));} catch(Error\Card $e) {
$status = "error: " . $e;
} catch(Error\Card $e) {
// The card has been declined
$status = "declined: " . $e;
}
}
else
{
//echo "missing params";
$status = "missing params";
}
You may check their docs. In this page they show how to get the token in different languages (Java, PHP and so on, and not only in JavaScript, as showed in their step-by-step guide)
https://stripe.com/docs/api#token_object

Categories