I'm trying to make a little shopping cart with CodeIgniter and I found CI-Merchant to work with payment gateways with this guide http://ci-merchant.org/ but I don't really understand how to make it works with Paypal Sandbox.
$this->load->library('merchant');
$this->merchant->load('paypal_express');
$settings = array(
'username' => 'test#test.com',
'password' => '********',
'signature' => 'Test Store',
'test_mode' => true);
$this->merchant->initialize($settings);
$params = array(
'amount' => 12.00,
'currency' => 'CAD',
'return_url' => 'http://payment.test.com',
'cancel_url' => 'http://payment.test.com/cancel');
$response = $this->merchant->purchase($params);
$this->load->view('welcome_message');
I know that this code can't do much but it do nothing at all. Just load the view and nothing happens, I don't understand. So, my question is, do you know tutorials or just how to make CI Merchant works with Paypal Sandbox? Thanks for the help.
Ace's comment is spot on. There is nothing wrong with your code, but you need to inspect the $response object to see what the result (or error message) was.
$response = $this->merchant->purchase($params);
if ($response->success())
{
// mark order as complete
$gateway_reference = $response->reference();
}
else
{
$message = $response->message();
echo('Error processing payment: ' . $message);
exit;
}
You can also simply try this to inspect the object:
$response = $this->merchant->purchase($params);
echo '<pre>';
print_r($response);
exit;
Related
I've been trying to get the saved customer id for stripe from database but with no luck.
It works everywhere else, I could get it and save it again if I wanted, but whenever I try to use it in payment intent to automatically renew a subscription, it gives me this error: Trying to get property 'stripecustomerid' of non-object.
this is the bit of the stripe code for recurring charge where the error happens:
public function renew($subscription)
{
\Stripe\Stripe::setApiKey('sk_test_XXXXXXXX');
header('Content-Type: application/json');
try {
$json_str = file_get_contents('php://input');
$json_obj = json_decode($json_str);
$user = \Auth::user();
$payment_methods = \Stripe\PaymentMethod::all([
'customer' => $user->stripecustomerid,
'type' => 'card'
]);
$payment_intent = \Stripe\PaymentIntent::create([
'amount' => $subscription->plan->stripePrice(),
'currency' => 'usd',
'customer' => $user->stripecustomerid,
'payment_method' => $payment_methods->data[0]->id,
'off_session' => true,
'confirm' => true,
]);
echo json_encode([
'paymentIntent' => $payment_intent,
]);
}
catch (\Exception $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}
}
and stripecustomerid is the name of the column where I saved the customer id.
I can print it in another function, and it works when I use GET, but it just doesn't work when the subscription tries to renew.
I have setup a checkout system with Ominpay and Paypal express and it worked fine in test mode so I just went 'live' with it. Unfortunately I didn't check whether all the information was sent to paypal after checkout. It seems only the amount and currency are getting sent and not the description/name of the products. This means the seller doesn't know what got sold!
N.B: Everything gets sent to the Paypal checkout page fine. But after payment is made the product names don't show up on the seller's paypal page - only the quantity and price do.
How can I get the product names to show up on the seller's paypal account? It will be an array because multiple products will be sold.
If it helps here's the site: http://threemarchhares.sukeates.com/
I'm using Laravel 4. My payments controller:
public function postPayment() {
$cart = Session::get('cart');
$allProducts = [];
foreach($cart->aContents as $productID=>$quantity){
$product = Product::find($productID);
$allProducts[] = array('name' => $product->name, 'quantity' => $quantity, 'price'=> $product->price);
}
$params = array(
'cancelUrl' => \URL::to('cancel_order'),
'returnUrl' => \URL::to('payment_success'),
'amount' => Input::get('price'),
'currency' => Input::get('currency'),
'description' => Input::get('name'), //I assume this is wrong as it doesn't work.
);
Session::put('params', $params);
Session::save();
$gateway = Omnipay::create('PayPal_Express');
$gateway->setUsername('*****');
$gateway->setPassword('****');
$gateway->setSignature('***');
$gateway->setTestMode(false);
$response = $gateway->purchase($params)->setItems($allProducts)->send();
$data = $response->getData();
if ($response->isSuccessful()) {
// payment was successful: update database
print_r($response);
} elseif ($response->isRedirect()) {
// redirect to offsite payment gateway
$response->redirect();
} else {
// payment failed: display message to customer
echo $response->getMessage();
}
}
public function getSuccessPayment()
{
$gateway = Omnipay::create('PayPal_Express');
$gateway->setUsername('****');
$gateway->setPassword('****');
$gateway->setSignature('*****');
$gateway->setTestMode(false);
$params = Session::get('params');
$response = $gateway->completePurchase($params)->send();
$paypalResponse = $response->getData(); // this is the raw response object
if(isset($paypalResponse['PAYMENTINFO_0_ACK']) && $paypalResponse['PAYMENTINFO_0_ACK'] === 'Success') {
etc
Your assumption is correct. It is a bad idea in general to fill payment data from input. Instead you should use data from your product:
'amount' => $product->price,
'currency' => 'USD',
'description' => $product->description,
Otherwise the user can modify the price in html and enjoy cheap checkout ;)
You need to send the item information again, when you send the 'completePurchase' request.
$response = $gateway->completePurchase($params)->setItems($allProducts)->send();
Ok, this might have a very simple answer but for the life of me my I can not seem to find an answer! I am signing up users from a text into a lights out box (SimpleModal) which AJAX loads a new page for an admin to sign up a user to a selected client list.
This all works without any issues at all, so long as the model checks are correct. I have two checks, one makes sure the username is unique and that the password has at lest 8 characters, code below. But when one or both of these checks are not meet, then the user is taken to the AJAX URL and the 'message' is then displayed. This is not what I need I need it to be taken back to the lights out box or set these messages as flash error message to be printed on to the screen.
Or should I remove these checks from the modal and get JQuery to check them instead?
Any ideas?
All help very welcome.....
Model Code ::
public $validate = array(
'username' => array(
'required' => array(
'rule' => array('isUnique'),
'message' => 'Sorry but a unique username is required'
)
),
'password' => array(
'required' => array(
'rule' => array('minLength', '8'),
'message' => 'Sorry but a password of 8 characters or more is required'
)
) ... more check follow but these are the issues....
CTP file ::
$this->layout = 'ajax';
$AddUserForm = $this->Form->create('User', array('url' => '/ADD-USER-URL-HERE'));
$AddUserForm .= $this->Form->input('username');
$AddUserForm .= $this->Form->input('password');
$AddUserForm .= $this->Form->input('role', array('options' => array('admin' => 'Admin', 'user' => 'User')));
$AddUserForm .= $this->Form->input('data_id', array('options' => array($data), 'empty'=>true));
$AddUserForm .= $this->Form->end(__('SAVE NEW USER'));
echo $AddUserForm;
In your ctp file
$('form').on('submit', function(e) {
e.preventDefault();
$.post($(this).attr('action'), $(this).serialize(), function(res) {
$('form').replaceWith(res);
})
})
can be used for validating the data using the above script,
I think this will help you for submitting the form via ajax and you can also display the error messages using the response coming from the ajax.
Hope this will help you.
I want to send a POST request to an https server.
$data = 'name=value&name1=value1';
$options = array(
'method' => 'POST',
'data' => $data,
'timeout' => 15,
'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);
$result = drupal_http_request('http://somewhere.com', $options);
I can't figure out out to implement the https options in the POST example code above.
Can anyone please explain me how to do this? I am quite new to PHP coding with Drupal, and I could definitely use the guidance.
I found that all is needed is to set it in the protocol. So I got to this code.
$data = 'access_token=455754hhnaI&href=fb&template=You have people waiting to play with you, play now!';
$options = array(
'method' => 'POST',
'data' => $data,
'timeout' => 15,
'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);
$result = drupal_http_request('https://graph.facebook.com/1000721/notifications?', $options);
It still doesn't work. If I post via Firefox with https://graph.facebook.com/1000080521/notifications?access_token=45575FpHfhnaI&href=fb&template=You have people waiting to play with you, play now! it works.
I am probably not constructing the request properly in Drupal.
What am I doing wrong? How can I get my code to work?
There is no difference between using drupal_http_request() with a secure connection (https://), or without a secure connection (http://).
PHP must be compiled with support for OpenSSL; otherwise, drupal_http_request() doesn't support secure connections. Apart that, the only issue could be the proxy server not supporting a secure connection.
As side note, you are using https://graph.facebook.com/1000721/notifications? as URL for the request. The question mark should not be part of the URL.
I would also use drupal_http_build_query() to build the data to use for the request.
$data = array(
'access_token' => '455754hhnaI',
'href' => 'fb',
'template' => 'You have people waiting to play with you, play now!'
);
$options = array(
'method' => 'POST',
'data' => drupal_http_build_query($data),
'timeout' => 15,
'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);
$result = drupal_http_request('https://graph.facebook.com/1000721/notifications', $options);
i am making a custom phpbb3 registration and i am trying to register a user form a external file but it not working . also i checked for errors . there is no error .can anyone help me out with where i am wrong . also if anyone has any easy idea how to add a new user record for phpbb3 please help me out with this .
<?php
$username = $_POST[username];
$password = $_POST[password];
$email_address = $_POST[email];
include('forums/common.php');
require('forums/includes/functions_user.php');
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('viewtopic');
global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
$user_row = array(
'username' => $username, //REQUIRED IN FORM
'user_password' => md5($password), //REQUIRED IN FORM
'user_email' => $email_address, //REQUIRED IN FORM
'group_id' => 0,//(int) $group_id,
'user_timezone' => $timezone = date(Z) / 3600,//(float) $data[tz],
'user_dst' => date(I),//$is_dst,
'user_lang' => $user->lang_name,//$data[lang],
'user_type' => USER_NORMAL,//$user_type,
'user_actkey' => '',//$user_actkey,
'user_ip' => $user->ip,
'user_regdate' => time(),
'user_inactive_reason' => 0,//$user_inactive_reason,
'user_inactive_time' => 0,//$user_inactive_time,
);
// Register user...
$user_id = user_add($user_row);
?>
You must define
define('IN_PHPBB', true);
In other case your script will exit immediately in common.php and other required files. You can see
if (!defined('IN_PHPBB'))
{
exit;
}
in every required file