I am working with the PayPal RESTful API.
https://developer.paypal.com/webapps/developer/docs/api/
How can I pass my consumers order items and purchase description to PayPal, so when my user is redirected to PayPal to approve the order by logging in, their order summary will show up on the left.
.
.
ORDER SUMMARY ON THE LEFT
I have tried to passing in the transactions.item_list.items but that information isn't showing up in the order summary still.
Any help how to get an order summary to appear on the paypal approval page using the PayPal RESTful API?
I haven't been to pleased with their documentation as it is lacking some information and also has a few mistakes which wasted decent amount of my time to debug.
//
// prepare paypal data
$payment = array(
'intent' => 'sale',
'redirect_urls' => array(
'return_url' => $url_success,
'cancel_url' => $url_cancel,
),
'payer' => array(
'payment_method' => 'paypal'
)
);
//
// prepare basic payment details
$payment['transactions'][0] = array(
'amount' => array(
'total' => '0.03',
'currency' => 'USD',
'details' => array(
'subtotal' => '0.02',
'tax' => '0.00',
'shipping' => '0.01'
)
),
'description' => 'This is the payment transaction description 1.'
);
//
// prepare individual items
$payment['transactions'][0]['item_list']['items'][] = array(
'quantity' => '1',
'name' => 'Womens Large',
'price' => '0.01',
'currency' => 'USD',
'sku' => '31Wf'
);
$payment['transactions'][0]['item_list']['items'][] = array(
'quantity' => '1',
'name' => 'Womens Medium',
'price' => '0.01',
'currency' => 'USD',
'sku' => '31WfW'
);
//
//format payment array to pass to cURL
$CURL_POST = json_encode($payment);
your code is good. This is actually a bug that will be fixed very soon. Regarding documentation, can you share how we can make it better? I want to make sure your feedback gets passed to our documentation team.
I experienced the same issue while trying it out today. What I did was add the Items like below.
$item = new Item();
$item->setQuantity($item_quantity);
$item->setName($item_name);
$item->setPrice($item_price);
$item->setCurrency($item_currency);
$item_list = new ItemList();
$item_list->setItems(array($item));
The $item_list is a property of transaction so you should add it after.
$transaction = new Transaction();
$transaction->setItemList($item_list);
....
That should show on the Order summary pane on PayPal page.
You can also check the answer here.
Try using the sample shown here : http://htmlpreview.github.io/?https://raw.githubusercontent.com/paypal/PayPal-PHP-SDK/master/sample/doc/payments/CreatePaymentUsingPayPal.html
It is a sample that comes along with the PayPal REST API SDK. You can try those samples out yourselves, by following instructions on readme.
This is how it would look like, when you run that sample:
Related
I am trying to set Stripe checkout for my website.
I created and verified my Stripe account, and now I need to set up the checkout page. I downloaded from Github the PHP stripe library (I have PHP 5.6.4, so compatibility is OK). Then I went in the Stripe documentation and found this page.
I created a new page for the checkout, included the init.php from the Stripe library and pasted in the page the code found in the documentation page. When I open it, it gives back an empty page but I don't know why.
I don't know if this is the right procedure, but I searched online for like 2 hours finding nothing, and the documentation doesn't seem clear to me. Can someone help me?
I checked and the page doesn't generate errors. The code of the page is this:
<?php
require_once('assets/stripe/init.php');
\Stripe\Stripe::setApiKey('sk_test_OW6K5e96gNXbAhEvPo15IB3C');
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'name' => 'T-shirt',
'description' => 'Comfortable cotton t-shirt',
'images' => ['https://example.com/t-shirt.png'],
'amount' => 500,
'currency' => 'eur',
'quantity' => 1,
]],
'success_url' => 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => 'https://example.com/cancel',
]);
?>
This is what I copied in the page, still don't know if there's something to change or some other things to add.
<?php
require_once 'shared.php';
$domain_url = $config['domain'];
$base_price = $config['base_price'];
$currency = $config['currency'];
$quantity = $body->quantity;
// Create new Checkout Session for the order
// Other optional params include:
// [billing_address_collection] - to display billing address details on the page
// [customer] - if you have an existing Stripe Customer ID
// [payment_intent_data] - lets capture the payment later
// [customer_email] - lets you prefill the email input in the form
// For full details see https://stripe.com/docs/api/checkout/sessions/create
// ?session_id={CHECKOUT_SESSION_ID} means the redirect will have the session ID set as a query param
$checkout_session = \Stripe\Checkout\Session::create([
'success_url' => $domain_url . '/success.html?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => $domain_url . '/canceled.html',
'payment_method_types' => ['card'],
'line_items' => [[
'name' => 'Pasha photo',
'images' => ["https://picsum.photos/300/300?random=4"],
'quantity' => $quantity,
'amount' => $base_price,
'currency' => $currency
]]
]);
echo json_encode(['sessionId' => $checkout_session['id']]);
for more details and demo code :
https://github.com/stripe-samples/checkout-one-time-payments/tree/master/client-and-server/server/php/public
I am using mindbody api for payment, when I add my credit card detail then payment is successful but when I am using stored(existing) card for payment then it's given error :
Card Authorization Failed mb.Core.BLL.Transaction failed validation Could not determine the type of credit card.
my code is:
$shoppingCart = array(
'ClientID' => $client_id,
'Test' => false,
'InStore' => true, //add by NIK
'CartItems' => array(
'CartItem' => array(
'Quantity' => $product_qty,
'Item' => new SoapVar(
array('ID' => $product_id), SOAP_ENC_ARRAY, 'Service', 'http://clients.mindbodyonline.com/api/0_5'
),
'DiscountAmount' => 0
)
),
'Payments' => array(
'PaymentInfo' => new SoapVar(
array(
'LastFour'=>$clientCreditCard->LastFour,
'Amount'=>round($OnlinePrice, 2),
),
SOAP_ENC_ARRAY,
'StoredCardInfo',
'http://clients.mindbodyonline.com/api/0_5'
),
)
);
please give any solution for it, what should I do or send extra parameter.
thanks!
Shouldn't it look more like this?
'Payments' => array(
'PaymentInfo' => new SoapVar(
array(
'CreditCardNumber'=>'4111111111111111',
'ExpYear'=>'2015',
'ExpMonth'=>'06',
'Amount'=>'130',
'BillingAddress'=>'123 Happy Ln',
'BillingPostalCode'=>'93405'
),
SOAP_ENC_ARRAY,
'CreditCardInfo',
'http://clients.mindbodyonline.com/api/0_5'
)
Taken from this README.md https://github.com/devincrossman/mindbody-php-api
Your shopping cart array with saved card is correctly constructed.
I've been struggling with exactly the same problem for the last few days, and I found that the error in my case was that the front end account page was passing the credit card number with spaces in the string - the front end form was automatically adding the spaces for the usual format/usability reasons in the admin part of the application where the saved card details are entered.
I solved it by stripping out the spaces in PHP : str_replace(" ", "", $_POST['cardnumber']) in the card save function.
Once I did that the saved card payment process worked fine.
I create a APP in which i use Braintree Payment Gateway. In my application i make options to set different currency, am just know that how to set currency when i set sale transaction param.
here is my code
$result = Braintree\Transaction::sale([
'amount' => '50.00',
'creditCard' => array(
'cardholderName' => 'Test Name',
'number' => '4000111111111511',
'expirationDate' => '12/2018',
'cvv' => '123',
),
'options' => [ 'submitForSettlement' => true]
]);
All of my transaction made in US Dollar, but i want to make transaction in different currencies.
Please someone give me the solution.
thanks
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
You will need to set up a different merchant account for each currency you would like to process. Then, when processing a transaction for a specific currency, you can pass in the merchant account id to the transaction sale method.
In addition, to keep your PCI compliance burden low, you will want to pass a nonce to your server in place of the credit card details.
$merchantAccountId = someFunctionToLookupCorrectMerchantIdBasedOnCurrency();
$result = Braintree\Transaction::sale([
'amount' => '100.00',
'paymentMethodNonce' => nonceFromTheClient,
'merchantAccountId' => $merchantAccountId,
'options' => [
'submitForSettlement' => True
]
]);
I am trying to create a coupon in big commerce using their API. I am using the following code after connecting with the store.
$coupon = array('name' => 'somecoupon', 'type' => 'percentage_discount', 'amount' => '50.0', 'code' => '50off', 'enabled' => true);
echo Bigcommerce::createCoupon($coupon);
I simply copied the code from their
Support Page
All the other codes on that page work but create coupon doesnt work. If I use get coupons codes, they work perfectly but creating coupon is not working what so ever. Any ideas on this?
Any help would be highly appreciated.
Thanks
The developer page neglects to mention that 'applies_to' is also a required field, hence why your code is failing.
Try
$coupon = array('name' => 'somecoupon', 'type' => 'percentage_discount', 'amount' => '50.0', 'code' => '50off', 'enabled' => true, 'applies_to'=> array('entity' => 'categories', 'ids' => array('value' => 0)));
echo Bigcommerce::createCoupon($coupon);
Recently I'm playing with paypal API PHP.
I have downloaded a code from this url.
https://github.com/paypal/rest-api-curlsamples/blob/master/execute_all_calls.php
The code really works good with test creditcard(type:mastercard). The code looks like this
$url = $host.'/v1/payments/payment';
$payment = array(
'intent' => 'sale',
'payer' => array(
'payment_method' => 'credit_card',
'funding_instruments' => array ( array(
'credit_card' => array (
'number' => '540xxxxxxxxxxxx6',
'type' => 'mastercard',
'expire_month' => 12,
'expire_year' => 2018,
'cvv2' => 111,
'first_name' => 'First Name',
'last_name' => 'Last Name'
)
))
),
'transactions' => array (array(
'amount' => array(
'total' => '2',
'currency' => 'USD'
),
'description' => 'payment by a credit card using a test script'
))
);
Now if i try to use the same code to make the payment using my VISA(American Express) with test card number 37xxxxxxxxxx005, how shall i obtain this? What are the parameters to be altered?
In other words I would like to make the payment using Diner's Club,Discover and JCB. How shall I achieve this?
Edit: I have got two comments from Stack Overflow users, and you can check it at the bottom of my question. I'm not clear with the comments. Do they tell that I don't need to think about the parameters and paypal will take care of the card details and make the transaction?
Got reply from Paypal Tech Team for my above question
{snip}
You need to alter the code for 'type'. Below shows the code for the credit card type :l
- Visa
- MasterCard
- Discover
- Amex
And also make sure you need to input correct credit card number based on the type if you not you will receive an error message.
{/snip}
In other words, it is more than enough if I change the 'type' => 'mastercard' to 'type' => 'visa' (or) 'type' => 'amex' (or) 'type' => 'discover'
And also please make sure you give the correct test card numbers. You can view the dummy credit card numbers here.
http://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card_numbers.htm
Hope this will help someone if they are struck with the paypal PHP API integration.
Thanks for all the tech support & SOF-Users.
Thanks again,
Haan