PayPal Checkout without Details and Subtotal - paypal

I use the PayPal SDK for PHP and want to go to the checkout without showing details and total instead of subtotal (like on the picture left).
Thanks!
Example Picture
This is the Code i use.
$arrPrices = $this->getPrices();
$apiContext = $this->getApiContext();
$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod("paypal");
$arrItems = [];
$item = new \PayPal\Api\Item();
$item->setName($saveValues['title'])->setCurrency('EUR')->setQuantity(1)->setPrice($arrPrices['raw']);
$arrItems[] = $item;
$itemList = new \PayPal\Api\ItemList();
$itemList->setItems($arrItems);
$details = new \PayPal\Api\Details();
$details->setTax($arrPrices['tax'])->setSubtotal($arrPrices['raw']);
$amount = new \PayPal\Api\Amount();
$amount->setCurrency("EUR")->setTotal($arrPrices['total'])->setDetails($details);
$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription("Vielen Dank für Deine Buchung & bis bald!");
$redirectUrls = new \PayPal\Api\RedirectUrls();
$url = \Environment::get('url') . '/' . $GLOBALS['SCRIPT_URL'];
$redirectUrls->setReturnUrl("$url?success=true")->setCancelUrl("$url?success=false");
$payment = new \PayPal\Api\Payment();
$payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->addTransaction($transaction);
try {
$payment->create($apiContext);
}
catch (\Exception $ex) {
return $ex->getData();
}
return $payment->getApprovalLink();

If you don't provide the details you will not see the details ? there isn't a way by which you will provide the details and then not have display it on the paypal approval page (of which you are showing the screen shot)

Related

How I can move contact from one list to another using PHP API

I am using PHP SDK for constant contact plugin. I want to move contact from one list to another. I have tried following code it will generate BAD response error.
$action = "Updating Contact";
$contact = $response->results[0];
foreach ($contact->lists as $key => $value) {
unset($contact->lists[$key]);
}
$cc->contactService->updateContact(WPYog_ACCESS_TOKEN, $contact,true);
$contact->addList((string)$_POST['list_id']);
$contact->first_name = 'Sudhir';
$contact->status = 'ACTIVE';
$contact->email_addresses[0]->status = 'ACTIVE';
$contact->last_name = 'Pandey';
try {
$cc->contactService->updateContact(WPYog_ACCESS_TOKEN, $contact,true);
}catch (CtctException $ex) {
var_dump($ex->getErrors());
}
I have found answer. First of all fetch the record by using this
$action = "Updating Contact";
$contact = $response->results[0];
// Now empty the list
$contact->lists = array();
$contact->addList((string)$_POST['list_id']);
$contact->first_name = 'Sudhir';
$contact->status = 'ACTIVE';
$contact->email_addresses[0]->status = 'ACTIVE';
$contact->last_name = 'Pandey';
try {
$cc->contactService->updateContact(WPYog_ACCESS_TOKEN, $contact,true);
}catch (CtctException $ex) {
var_dump($ex->getErrors());
}

Retrieve Lead Ads Facebook API

I have problems retrieving Lead Ads.
I have the Ad-ID and the Page-ID. I haven't created them, but was added as a developer.
I was trying to use the PHP SDK and this https://developers.facebook.com/docs/marketing-api/guides/lead-ads/v2.9
Nothing is working. I cannot find a nice tutorial about that.
I just want to retrieve the leading Ads!
Anyone?
Assuming you have already installed FB API SDK and configured your FB app, you can use this to get all results from all LeadAds of your $page_id
use FacebookAds\Api;
use FacebookAds\Object\Page;
use FacebookAds\Object\Ad;
$access_token = 'YOUR TOKEN';
$app_id = 'YOUR APP ID';
$app_secret = 'YOUR APP SECRET';
$page_id = 'YOUR PAGE ID';
Api::init($app_id, $app_secret, $access_token);
$ads = getAllLeadsAds($page_id);
$result = array();
foreach ($ads->data as $item) {
$leads = getLeadAdInfo($item->id);
$i = 0;
foreach ($leads->data as $value) {
$result[$i]['ad_id'] = $item->id;
$result[$i]['lead_id'] = $value->id;
$result[$i]['form'] = $value->field_data;
$i++;
}
}
print_r($result);
function getAllLeadsAds($page)
{
$page = new Page($page);
return $page->getLeadgenForms()->getResponse()->getBody();
}
function getLeadAdInfo($ad)
{
$ad = new Ad($ad);
return $ad->getLeads()->getResponse()->getBody();
}
Its possible that you not calling all ads inside adset.
You can use facebook cursor.
$cursor->fetchAfter();
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Values\ArchivableCrudObjectEffectiveStatuses;
use FacebookAds\Object\Fields\CampaignFields;
use FacebookAds\Object\AdCampaign;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdFields;
use FacebookAds\Object\Ad;
use FacebookAds\Object\Campaign;
function getadsetname($adset_id,$acc_id){
$adset = new AdSet($adset_id, $acc_id);
$adset->read(array(
AdSetFields::NAME,
));
return $adset->name; // Outputs name of adset.
}
function get_campaignname($campaign_id){
$campaign = new Campaign($campaign_id);
$campaign->read(array(
CampaignFields::NAME,
));
return $campaign->name;
}
$account = new AdAccount($account_id);
echo $adset_name = getadsetname($adset_id,$account_id);
echo $campaign_name = get_campaignname($campaign_id);
echo "<hr>";
$adcampaign = new AdAccount($campaign_id);
$adset = new AdSet($adset_id);
$ads = $adset->getAds(array(
AdFields::NAME,
AdFields::CONFIGURED_STATUS,
AdFields::EFFECTIVE_STATUS,
AdFields::CREATIVE,
));
$ads->fetchAfter();
foreach ($ads as $ad) {
$ad_id = $ad->id;
$ad_name = $ad->name;
if($ad->configured_status=="ACTIVE"){
$ad1 = new Ad($ad_id);
$leads = $ad1->getLeads();
$leads->fetchAfter();
foreach ($leads as $lead) {
$fname = $lead->field_data;
//var_dump($fname);
$data = array();
$data['lead_id'] = $lead->id;
$data['created_time'] = $lead->created_time;
$data['ad_id'] = $ad_id;
$data['ad_name'] = $ad_name;
$data['adset_id'] = $adset_id;
$data['adset_name'] = $adset_name;//$adset_name;
$data['campaign_id'] = $campaign_id;
$data['campaign_name'] = $campaign_name;
$data['form_id'] = $lead->form_id;//$lead->id;
$data['is_organic'] = $lead->is_organic;//$lead->id;
}
}
}
$ads->fetchAfter(); will get the next list of ads and
$leads->fetchAfter(); will get the next list of leads

PayPal Rest API complete the payment but not shown in sandbox transactions

I created a PHP script with PayPal Rest API. When I complete the payment the site redirect to the finish page with the label of the payment success, but when I go to the sandbox paypal site, I can't see any transactions. What I can do for solve this issue?
Here there are the 3 scripts:
start.php
<?php
require 'vendor/autoload.php';
define('SITE_URL', 'http://192.168.1.105/Fenix/Include/pay.php');
$paypal = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'AX5IC3G3s-XRzfMgmSUjEPGbHAjD6PL80skf7Xck50OKWXQ2nGf-9NWk5FjSaMCh1FPpxFvUioqZEbjy',
'EJ8GDd08PwnRM1VxYzT2-fBmxAYzykYZ_zlwHi_zqmFGOQzaoXHAffM5DSiBDTcd8L6OpyDzGt5gtmMU'
)
);
?>
checkout.php
<?php
include "./vendor/autoload.php";
use PayPal\Api\Payer;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Details;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Payment;
require 'start.php';
/*
if (!isset($_POST['product'], $_POST['price'])){
die();
}
*/
$product = "Fenix ID";
$price = 0.01;
$shipping = 0;
$total = $price+$shipping;
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item = new Item();
$item->setName($product)
->setCurrency('EUR')
->setQuantity(1)
->setPrice($price);
$itemList = new ItemList();
$itemList->setItems([$item]);
$details = new Details();
$details->setShipping($shipping)
->setSubtotal($price);
$amount = new Amount();
$amount->setCurrency('EUR')
->setTotal($total)
->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription('Fenix ID')
->setInvoiceNumber(uniqid());
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(SITE_URL . '/pay.php?success=true')
->setCancelUrl(SITE_URL . '/pay.php?success=false');
$payment = new Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions([$transaction]);
try {
$payment->create($paypal);
}catch (Exception $e){
die($e);
}
$approvalUrl = $payment->getApprovalLink();
header("Location: {$approvalUrl}");
?>
pay.php
<?php
use PayPal\Api\Payment;
use PayPal\Api\PaymentExecution;
require 'start.php';
if (!isset($_GET['success'], $_GET['paymentId'], $_GET['PayerID'])) {
die();
}
if ((bool)$_GET['success'] === false) {
die();
}
$paymentId = $_GET['paymentId'];
$payment = Payment::get($paymentId, $paypal);
$execution = new PaymentExecution();
$execution->setPayerId($_GET['PayerID']);
echo "Payment success!";
?>
Thanks for the help.

Paypal CC Direct Payment error

I need some help to figure out paypal's API, all I'm trying to do is run a cc charge to my sandbox account, I've been looking at their documentation and code samples but I just can't find the right information right now, like where to add the sandbox endpoint. So, when I run the function below I get the following error:
string(213) "{"name":"MALFORMED_REQUEST","message":"Incoming JSON request does not map to API request","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"6eb15180f8d92"}"
This is the function I'm calling:
public static function ccPayment($paymentInfo, $credentials)
{
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
$credentials['clientId'],
$credentials['secret']
)
);
$card = new CreditCard();
$card->setType("visa")
->setNumber("xxxxxxxxxxxxxxxx")
->setExpireMonth("11")
->setExpireYear("2019")
->setCvv2("012")
->setFirstName("Joe")
->setLastName("Shopper");
$fi = new FundingInstrument();
$fi->setCreditCard($card);
$payer = new Payer();
$payer->setPaymentMethod("credit_card")
->setFundingInstruments(array($fi));
$item1 = new Item();
$item1->setName('Ground Coffee 40 oz')
->setDescription('Ground Coffee 40 oz')
->setCurrency('USD')
->setQuantity(1)
->setTax(0.3)
->setPrice(7.50);
$itemList = new ItemList();
$itemList->setItems(array($item1));
$transaction = new Transaction();
$transaction->setAmount(489)
->setItemList($itemList)
->setDescription("Payment description")
->setInvoiceNumber(uniqid());
$payment = new Payment();
$payment->setIntent("sale")
->setPayer($payer)
->setTransactions(array($transaction));
// $request = clone $payment;
try
{
$payment->create($apiContext);
}
catch (Exception $ex)
{
dd($ex->getData());
}
dd($paymentInfo);
}
Been coding since the morning so I need another set of eyes right now because I just can't see what I'm doing wrong. I will appreciate any help.
PS. Apologies if it's something dumb. Eg. a missing comma.
Thanks.
Got it working !! Here's the working code:
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
$credentials['clientId'],
$credentials['secret']
)
);
$apiContext->setConfig(
array(
'log.LogEnabled' => true,
'log.FileName' => '../app/storage/paypal/PayPal.log',
'log.LogLevel' => 'FINE'
)
);
$card = new CreditCard();
$card->setType("visa")
->setNumber("xxxxxxxxxxxxxxxxx")
->setExpireMonth("11")
->setExpireYear("2019")
->setCvv2("012")
->setFirstName("Joe")
->setLastName("Shopper");
$fi = new FundingInstrument();
$fi->setCreditCard($card);
$payer = new Payer();
$payer->setPaymentMethod("credit_card")
->setFundingInstruments(array($fi));
$item1 = new Item();
$item1->setName('Ground Coffee 40 oz')
->setDescription('Ground Coffee 40 oz')
->setCurrency('USD')
->setQuantity(1)
->setPrice(49.99);
$itemList = new ItemList();
$itemList->setItems(array($item1));
$details = new Details();
$details->setSubtotal(49.99);
$amount = new Amount();
$amount->setCurrency("USD")
->setTotal(49.99)
->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription("Payment description")
->setInvoiceNumber(uniqid());
$payment = new Payment();
$payment->setIntent("sale")
->setPayer($payer)
->setTransactions(array($transaction));
try
{
$payment->create($apiContext);
}
catch (Exception $ex)
{
dd($ex->getData());
}
dd($payment);
I was missing new Amount & new Details. Also, for the sake of documentation, your monetary totals must add up. Eg. tax, subtotal, total.

Masspay can not pay

I receive the following error when I try to send money using masspay api through my site backend : "The input to the masspay server is incorrect. Please make sure that you are using a correctly formatted input. , Masspay not complete"
The result is that money don't transfer.
This only happens when the amount has decimal digits. For instance 4.25€. It's NOT happening when I try to send non decimal amounts, for instance 10€, 20€ or other.
What is happening?
Thanks
if (!empty($userCashWithdrawalId) && !empty($cash_withdraw)) {
$data['Transaction']['user_id'] = ConstUserIds::Admin;
$data['Transaction']['foreign_id'] = $cash_withdraw['UserCashWithdrawal']['user_id'];
$data['Transaction']['class'] = 'SecondUser';
$data['Transaction']['amount'] = $cash_withdraw['UserCashWithdrawal']['amount'];
$data['Transaction']['description'] = 'User cash withdrawal request approved by admin';
$data['Transaction']['transaction_type_id'] = ConstTransactionTypes::AdminApprovedWithdrawalRequest;
$this->UserCashWithdrawal->User->Transaction->log($data);
$transaction_id = $this->UserCashWithdrawal->User->Transaction->getLastInsertId();
$data = array();
$data['Transaction']['user_id'] = $cash_withdraw['UserCashWithdrawal']['user_id'];
$data['Transaction']['foreign_id'] = ConstUserIds::Admin;
$data['Transaction']['class'] = 'SecondUser';
$data['Transaction']['amount'] = $cash_withdraw['UserCashWithdrawal']['amount'];
$data['Transaction']['description'] = 'User cash withdrawal request approved by admin';
$data['Transaction']['transaction_type_id'] = ConstTransactionTypes::AmountApprovedForUserCashWithdrawalRequest;
$this->UserCashWithdrawal->User->Transaction->log($data);
// update log transaction id
$paypal_log_array = array();
$paypal_log_array['PaypalTransactionLog']['id'] = $status['paypal_log_list'][$userCashWithdrawalId];
$paypal_log_array['PaypalTransactionLog']['transaction_id'] = $transaction_id;
$this->loadModel('PaypalTransactionLog');
$this->PaypalTransactionLog->save($paypal_log_array);
// update status
$user_cash_data = array();
$user_cash_data['UserCashWithdrawal']['id'] = $userCashWithdrawalId;
$user_cash_data['UserCashWithdrawal']['withdrawal_status_id'] = ConstWithdrawalStatus::Approved;
$this->UserCashWithdrawal->save($user_cash_data);
}
}
$messageType = 'success';
$flash_message = __l('Mass payment request is submitted in Paypal. User will be paid once process completed.');
} **else {
$user_count = count($status['paypal_log_list']);
$flash_message = '';
for ($i = 0; $i < $user_count; $i++) {
if (!empty($status['paypal_response']['L_LONGMESSAGE' . $i])) {
$flash_message.= urldecode($status['paypal_response']['L_LONGMESSAGE' . $i]) . ' , ';
}
}
$messageType = 'error';
$flash_message.= __l(' Masspay not completed');**