Please help me.
I'm trying to integrate omnipay/paypal to process payments. Everythings works great until i need to verify my payment. How i register payment:
$gateway = Omnipay::create('PayPal_Rest');
$gateway->initialize(array(
'clientId' => $config['paypal_client_id'],
'secret' => $config['paypal_secret'],
'testMode' => true, // Or false when you are ready for live transactions
));
$response = $gateway->purchase(array(
'amount' => $data['price_sum'],
'currency' => 'PLN',
'description' => 'NNÅ»: ' . $description . $data['order_id'],
'transactionId' => $data['order_id'],
'returnUrl' => $app_url . 'basket/pay?token=' . $data['token'],
'cancelUrl' => $app_url . 'basket/pay?token=' . $data['token'],
'notifyUrl' => $app_url . 'payment/verify-basket-paypal'
))->send();
//print_r( get_class_methods( $response ) );
// Process response
if ($response->isSuccessful()) {
$transaction_id = $response->getTransactionReference();
Kernel::log('paypal.log' , $transaction_id);
return ['url' => $response->getRedirectUrl(), 'paypal' => true ];
} elseif ($response->isRedirect()) {
// Redirect to offsite payment gateway
$response->redirect();
} else {
// Payment failed
echo $response->getMessage();
}
On html page i've added button with url ($response->getRedirectUrl()) after that, i'm redirected to same page, where i want to verify, if payment is booked right.
Url has additional GET params:
/payment/verify-basket-paypal?paymentId=PAYID-L37QMOY42K85628E4550351P&token=EC-3SM080895T541133U&PayerID=Y3DZ53CGGL47N
I've try something like this:
$gateway = Omnipay::create('PayPal_Rest');
$gateway->initialize(array(
'clientId' => $config['paypal_client_id'],
'secret' => $config['paypal_secret'],
'testMode' => true, // Or false when you are ready for live transactions
));
$transaction = $gateway->fetchTransaction([
'paymentId' => $request->get['paymentId'],
'token' => $request->get['token'],
'PayerID' => $request->get['PayerID']
]);
but it isn't working. Please help, how can i verify payment. There are no additional documentation on their page. Thanks a lot.
Related
I'm trying to create a customer before i charge them. on my charge.php file i have this.
if (isset($_POST['stripeToken'])) {
\Stripe\Stripe::setApiKey('___stripe_secret_key_____');
$api_error = false;
$token = $_POST['stripeToken'];
try {
$customer = \Stripe\Customer::create(array(
"name" => $name,
"email" => $email,
"source" => $token,
"metadata" => ['id' => $uid]
));
$stripe_id = $customer->id;
//update stripe ID to DB
User::model()->updateByPk($uid, array('stripe_id' => $stripe_id));
} catch(Exception $e) {
$api_error = $e->getMessage();
}
if(empty($api_error) && $stripe_id) {
try {
$charge = \Stripe\Charge::create(
array(
'customer' => $stripe_id, //customer id
'amount' => $_POST['stripe-amount'],
'currency' => strtolower($_POST['stripe-currency']),
'description' => 'US Report',
'metadata' => [
'Currency' => $_POST['stripe-currency'],
'Invoice' => $_POST['ref_id'],
],
'receipt_email' => $email,
), array (
'idempotency_key' => preg_replace('/[^a-z\d]/im', '', $_POST['idempotency']),
)
);
} catch(\Stripe\Exception\CardException $e) {
// Since it's a decline, \Stripe\Exception\CardException will be caught
$api_error = 'Status is:' . $e->getHttpStatus() . '<br />';
$api_error .= 'Type is:' . $e->getError()->type . '<br />';
$api_error .= 'Code is:' . $e->getError()->code . '<br />';
// param is '' in this case
$api_error .= 'Param is:' . $e->getError()->param . '<br />';
$api_error .= 'Message is:' . $e->getError()->message . '<br />';
}
I'm using my own HTML form for the credit card , expiry and ccv. and included https://js.stripe.com/v3/ in my page.
When i submit my payment i get this error
Charge creation failed! Status is:402
Type is:card_error
Code is:missing
Param is:card
Message is:Cannot charge a customer that has no active card
Any idea what i'm missing here?
The only path that I see here that would cause that error is if $_POST['stripeToken'] is blank or null. I don't see that you're checking for that. If you look in your Stripe Dashboard logs, you should be able to see the exact parameters sent by your script to the "create customer" endpoint.
Beyond that, if you're still stuck I'd send the request ID (req_xxx) to Stripe Support along with your example code so that someone can take a closer look.
Try to pass Stripe token in source parameter when creating the charge as well.
$charge = \Stripe\Charge::create(
array(
'customer' => $stripe_id, //customer id
'source' => $token,
'amount' => $_POST['stripe-amount'],
'currency' => strtolower($_POST['stripe-currency']),
'description' => 'US Report',
'metadata' => [
'Currency' => $_POST['stripe-currency'],
'Invoice' => $_POST['ref_id'],
],
'receipt_email' => $email,
), array (
'idempotency_key' => preg_replace('/[^a-z\d]/im', '', $_POST['idempotency']),
)
);
Didn't need this before, but I added it and now my code works again.
No idea why :p
\Stripe\Customer::createSource(
$stripe_id,
array('source' => $token)
);
Added this before my $charge = \Stripe\Charge::create()
Today I tried to switch over development code to a limited-release production environment and immediately ran into issues.
The QuickBooks Accounting API works fine, however when it comes to payments I am able to accept them in sandbox mode but production returns "400 Bad Request"
I'm using my production API keys, I'm accessing the production API endpoints (api.intuit.com as opposed to sandbox.api.intuit.com), and I know the query I'm sending should be fine since it works in sandbox mode (unique Request-Id, amount, token, and currency provided in request body, proper content-type header, etc)
I also know my API key is fine since it works with the QuickBooks Accounting API. I am able to create a customer and create an invoice, but when I attempt to collect payment on the invoice it throws up on me.
What could be going wrong? I can post any code snippets or errors required. I'm using Laravel 5.2 with a phpOauthLib wrapper written by lusitanian.
The code I'm using:
$oauth = OAuth::consumer('QuickBooks');
$oauth_token = unserialize(file_get_contents(storage_path("tokens/oauth.token")));
$storage = $oauth->getStorage();
$storage->storeAccessToken('QuickBooks', $oauth_token['access_token']);
$member = Member::find(Request::get('id'));
$query = urlencode("select * from customer where displayname = '" . $member->first_name . " " . $member->last_name . "'");
$result = json_decode($oauth->request("/v3/company/" . $oauth_token['company_id'] . "/query?query=" . $query, "GET"));
$donor = null;
if( !property_exists( $result->QueryResponse, 'Customer' ) ) {
$donor = $oauth->request("/v3/company/" . $oauth_token['company_id'] . "/customer", "POST", json_encode([
'DisplayName' => $member->first_name . " " . $member->last_name
]), array('Content-Type' => 'application/json'));
} else {
$donor = $result->QueryResponse->Customer[0];
}
$pledge = $oauth->request("/v3/company/" . $oauth_token['company_id'] . "/invoice", "POST", json_encode([
'Line' => [
[
'Amount' => '25.00',
'DetailType' => 'SalesItemLineDetail',
'SalesItemLineDetail' => [
'ItemRef' => [
'value' => '21'
]
]
]
],
'CustomerRef' => [
'value' => $donor->Id
]
]), array('Content-Type' => 'application/json'));
$pledge = json_decode( $pledge )->Invoice;
$guid = GUID();
/************** THIS IS THE LINE THAT FAILS: ***************/
$capture = $oauth->request("https://api.intuit.com/quickbooks/v4/payments/charges", "POST", json_encode([
'amount' => $amount,
'token' => Request::get('token'),
'currency' => "USD"
]), ['Content-Type' => 'application/json', 'Request-Id' => $guid]);
$capture = json_decode( $capture );
$payment = $oauth->request("/v3/company/" . $oauth_token['company_id'] . "/payment", "POST", json_encode([
'CustomerRef' => [
'value' => $donor->Id,
'name' => $donor->DisplayName
],
'TotalAmt' => $capture->amount,
'Line' => [
[
'Amount' => $capture->amount,
'LinkedTxn' => [
[
'TxnId' => $pledge->Id,
'TxnType' => 'Invoice'
]
]
]
]
]), ['Content-Type' => 'application/json']);
Again, this code worked perfectly with the sandbox API, but now it fails. Tonight I'll see what I can do to get the HTTP transaction (request and response)
I have an ecommerce website that redirects to a Paypal express checkout using Omnipay. It will correctly redirect the user to Paypal and return with a successful message with payerID and everything. However, it does not actually take any payment and it does not show up on our paypal account as any payment taken. I am not sure if this is a paypal issue or a configuration problem with Omnipay. I would imagine that Paypal handles this part of it but since it's not working (on our old site it works fine but we do not use Omnipay.)
$gateway = Omnipay::gateway('paypal');
//production
$gateway->setUsername('11111111');
$gateway->setPassword('1111111111');
$gateway->setSignature('111111111');
$cardInput = array(
'firstName' => $info['first_name_bill'],
'lastName' => $info['last_name_bill'],
'billingAddress1' => $info['street_address_1_bill'],
'billingAddress2' => $info['street_address_2_bill'],
'billingPhone' => $info['phone_bill'],
'billingCity' => $info['city_bill'],
'billingState' => $info['state_bill'],
'billingPostCode' => $info['zip_bill'],
'shippingAddress1' => $info['street_address_1_ship'],
'shippingAddress2' => $info['street_address_2_ship'],
'shippingPhone' => $info['phone_ship'],
'shippingCity' => $info['city_ship'],
'shippingState' => $info['state_ship'],
'shippingPostCode' => $info['zip_ship'],
);
$card = Omnipay::creditCard($cardInput);
//live
$response = Omnipay::purchase(
array(
'cancelUrl' => 'http://store.site.com/cart/cancel-payment',
'returnUrl' => 'http://store.site.com/cart/successful-payment',
'amount' => Input::get('total'),
'currency' => 'USD',
'card' => $card,
'description' => 'Stuff'
)
)->send();
if ($response->isSuccessful()) {
return Redirect('cart/successful-payment');
} elseif ($response->isRedirect()) {
$response->redirect(); // this will automatically forward the customer
} else {
return Redirect::back()->with('error', 'There was a problem. Please try again.');
}
} else {
return Redirect::to('cart/successful-payment');
}
So basically what this will do is redirect them to Paypal to make a payment then redirect back to our store. That all works fine. They can input their card number and then come back to our store after submitting it. The issue is after it gets return nothing happens through paypal. No orders or payment are exchanged.
In your return function, the function that gets called when this URL is executed: http://store.site.com/cart/successful-payment you need to call completePurchase. Something like this:
$gateway = Omnipay::gateway('paypal');
//production
$gateway->setUsername('11111111');
$gateway->setPassword('1111111111');
$gateway->setSignature('111111111');
$purchaseId = $_GET['PayerID'];
$response = $gateway->completePurchase([
'transactionReference' => $purchaseId
])->send();
// .. check $response here.
I am using Laravel with Omnipay for our ecommerce application. We direct the customers to Paypal to make their purchase. We require shipping and billing information prior to placing an order and we would like that information to continue to Paypal to make it easier for them. However, only the first name and last name are crossing over to Paypal correctly. We can also use email with no issues.
public function postPayment() {
//var_dump(Session::get('shipping_info')); die;
$info = Session::get('shipping_info');
$gateway = Omnipay::gateway('paypal');
//sandbox
$gateway->setUsername('xxxx');
$gateway->setPassword('xxxx');
$gateway->setSignature('xxx');
$gateway->setTestMode('true');
//production
// $gateway->setUsername('xxxx');
// $gateway->setPassword('xxxx');
// $gateway->setSignature('xxxx');
$cardInput = array(
'firstName' => $info['first_name_bill'],
'lastName' => $info['last_name_bill'],
'billingAddress1' => $info['street_address_1_bill'],
'billingAddress2' => $info['street_address_2_bill'],
'billingPhone' => $info['phone_bill'],
'billingCity' => $info['city_bill'],
'billingState' => $info['state_bill'],
'billingPostCode' => $info['zip_bill'],
'shippingAddress1' => $info['street_address_1_ship'],
'shippingAddress2' => $info['street_address_2_ship'],
'shippingPhone' => $info['phone_ship'],
'shippingCity' => $info['city_ship'],
'shippingState' => $info['state_ship'],
'shippingPostCode' => $info['zip_ship'],
);
$card = Omnipay::creditCard($cardInput);
// var_dump($card); die;
$response = Omnipay::purchase(
array(
'cancelUrl' => 'http://localhost/public/',
'returnUrl' => 'http://localhost/public/',
'amount' => Input::get('total'),
'currency' => 'USD',
'card' => $card,
'description' => 'Stuff'
)
)->send();
$response->redirect();
}
According to the docs https://github.com/omnipay/omnipay it should work with no issues. dumping the sessions reveals the correct billing and shipping parameters.
It was just needing a cache refresh.
I'm using the Paypal API to create a subscription system where there are two types of subscriptions
Monthly subscription (5dlls)
Annual subscription (50dlls)
I currently have the following code:
For setting the checkout:
public function do_purchase($type){
$this->load->library('paypal');
$requestParams = array(
'RETURNURL' => site_url('restaurant/get_purchase_details'),
'CANCELURL' => site_url('restaurant/afiliaturestaurante')
);
$orderParams = array(
'L_BILLINGTYPE0' => 'RecurringPayments',
'L_BILLINGAGREEMENTDESCRIPTION0' => 'Monthly',
'AMT' => 0
);
$paypal = new Paypal();
$response = $paypal -> request('SetExpressCheckout',$requestParams + $orderParams);
if(is_array($response) && $response['ACK'] == 'Success') { //Request successful
$token = $response['TOKEN'];
header( 'Location: https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=' . urlencode($token) );
}
}
For creating the recurring Paypal profile:
public function get_purchase_details(){
if( isset($_GET['token']) && !empty($_GET['token']) ) { // Token parameter exists
// Get checkout details, including buyer information.
// We can save it for future reference or cross-check with the data we have
$this->load->library('paypal');
$paypal = new Paypal();
$checkoutDetails = $paypal -> request('GetExpressCheckoutDetails', array('TOKEN' => $_GET['token']));
// Complete the checkout transaction
$requestParams = array(
'TOKEN' => $_GET['token'],
'PAYERID' => $checkoutDetails['PAYERID'],
'PROFILESTARTDATE' => '2014-03-7T05:38:48Z',
'DESC' => 'Monthly',
'BILLINGPERIOD' => 'Month',
'BILLINGFREQUENCY' => '1',
'AMT' => '5',
'CURRENCYCODE' => 'USD',
'COUNTRYCODE' => 'US',
'MAXFAILEDPAYMENTS' => '3',
);
$response = $paypal -> request('CreateRecurringPaymentsProfile',$requestParams);
if( is_array($response) && $response['ACK'] == 'Success') { // Payment successful
// We'll fetch the transaction ID for internal bookkeeping
$profileID = $response['PROFILEID'];
}
}
}
I need to use $type variable on get_purchase_details for setting the amount of the profile, how can I pass the variable through Paypal so I can user on the other function? I'm using a Paypal library for creating the cURL requests.
Thanks in advance
You could just set the value of $type in a session variable, and that would be available upon return from PayPal.
Alternatively, you could pass your $type value in the CUSTOM parameter of SetExpressCheckout and that way it'll be returned in the GetExpressCheckoutDetails response.