Get Transaction Id after completing Payment Objective c? - objective-c

I was trying to get transation Id when paypal payment is done that is on didCompletePayment method, i can get only these details
Confirmation: {
client = {
environment = sandbox;
"paypal_sdk_version" = "2.12.2";
platform = iOS;
"product_name" = "PayPal iOS SDK";
};
response = {
"create_time" = "2017-02-01T07:40:43Z";
id = "PAY-4RK70135CF912010FLCIZB5A";
intent = sale;
state = approved;
};
"response_type" = payment;
}
I don't find transation ID here. Can any one suggest me how to get transation Id in detail so that i can save that to database.
I found some Curl concepts but i'm not sure where to start with.Please give me some suggestions.
Thanks in advance

Related

Django how to maintain a session?

I'm developing an e-commerce site and I'm working on the shopping cart functionality. When the user is not connected I create a session for him so that he can add products to the basket which is normal, when the user decides to place this order I ask him to connect but when he connects he loses the session that I had created for him and another session is assigned to him. The cause is that once connected it loses all its products selected in the screen. After reading the documentation on django sessions I found nothing that could help me.
here is my code for more details:
models.py
class Cart(models.Model):
session_id = models.CharField(max_length=150)
product = models.ForeignKey(Products, on_delete=models.CASCADE)
quantity = models.PositiveIntegerField(default=0, validators=[MinValueValidator(1)])
updated = models.fields.DateTimeField(auto_now=True)
created = models.fields.DateTimeField(auto_now_add=True)
deleted = models.fields.BooleanField(default=False)
def __str__(self) -> str:
return str(self.product)
views.py
class FrontProductAddCart(View):
def post(self, request, product_pk):
session_id = request.session._get_or_create_session_key()
product = models.Products.objects.get(pk=product_pk)
objet, create = models.Cart.objects.get_or_create(session_id=session_id, product=product)
quantity = request.POST.get("quantity")
if quantity:
objet.quantity = quantity
objet.save()
else:
objet.quantity += 1
objet.save()
return HttpResponse(
"",
headers={
"HX-Trigger": json.dumps({
"product_add_cart": context_processors.get_total_number_products(request)
})
}
)

Deepstream 1 - n relation

I'm trying to build a user notification using Deepstream.io. I'm using deepstream.io-storage-mongodb for storage. My data structure:
User
=================
id - email - others
Notication
=================
userId - notification
I'm try to implement 1-n modelling deepsteam tutorial. But I can't understand how can I do this. How can I store pointer or how can I point towards a List ? Or how can I implement notification using deepstream ?
Thanks in Advance.
you can try as like as given below (I'm using JS):
Receive Notication
var client = deepstream( 'localhost:6020' );
client.login();
// Unique Identification for user
let uniqueId = `userId:${userId}`;
// Mongodb collection : Notification
statusRecord = client.record.getList("Notification/" + uniqueId);
statusRecord.subscribe(function(data) {
data.forEach(function(name) {
var record = client.record.getRecord(name);
record.whenReady(function(r) {
// all notification
console.log( "r ==> ", r.get() );
});
});
});
Send Notification
const ds = deepstream( 'localhost:6020' );
ds.login();
// userId
const list = this.ds.record.getList( `Notification/${userId}` );
// id for notification
let id = `Notification/${this.ds.getUid()}`;
let record = this.ds.record.getRecord(id);
record.set( {
message: 'information'// save notification data
});
list.addEntry(id);
Hope it will solve your problem.

Paypal Php Sdk - NotifyUrl is not a fully qualified URL Error

I have this code
$product_info = array();
if(isset($cms['site']['url_data']['product_id'])){
$product_info = $cms['class']['product']->get($cms['site']['url_data']['product_id']);
}
if(!isset($product_info['id'])){
/*
echo 'No product info.';
exit();
*/
header_url(SITE_URL.'?subpage=user_subscription#xl_xr_page_my%20account');
}
$fee = $product_info['yearly_price_end'] / 100 * $product_info['fee'];
$yearly_price_end = $product_info['yearly_price_end'] + $fee;
$fee = ($product_info['setup_price_end'] / 100) * $product_info['fee'];
$setup_price_end = $product_info['setup_price_end'] + $fee;
if(isset($_SESSION['discountcode_amount'])){
$setup_price_end = $setup_price_end - $_SESSION['discountcode_amount'];
unset($_SESSION['discountcode_amount']);
}
$error = false;
$plan_id = '';
$approvalUrl = '';
$ReturnUrl = SITE_URL.'payment/?payment_type=paypal&payment_page=process_agreement';
$CancelUrl = SITE_URL.'payment/?payment_type=paypal&payment_page=cancel_agreement';
$now = $cms['date'];
$now->modify('+5 minutes');
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
$cms['options']['plugin_paypal_clientid'], // ClientID
$cms['options']['plugin_paypal_clientsecret'] // ClientSecret
)
);
use PayPal\Api\ChargeModel;
use PayPal\Api\Currency;
use PayPal\Api\MerchantPreferences;
use PayPal\Api\PaymentDefinition;
use PayPal\Api\Plan;
use PayPal\Api\Patch;
use PayPal\Api\PatchRequest;
use PayPal\Common\PayPalModel;
use PayPal\Api\Agreement;
use PayPal\Api\Payer;
use PayPal\Api\ShippingAddress;
// Create a new instance of Plan object
$plan = new Plan();
// # Basic Information
// Fill up the basic information that is required for the plan
$plan->setName($product_info['name'])
->setDescription($product_info['desc_text'])
->setType('fixed');
// # Payment definitions for this billing plan.
$paymentDefinition = new PaymentDefinition();
// The possible values for such setters are mentioned in the setter method documentation.
// Just open the class file. e.g. lib/PayPal/Api/PaymentDefinition.php and look for setFrequency method.
// You should be able to see the acceptable values in the comments.
$setFrequency = 'Year';
//$setFrequency = 'Day';
$paymentDefinition->setName('Regular Payments')
->setType('REGULAR')
->setFrequency($setFrequency)
->setFrequencyInterval("1")
->setCycles("999")
->setAmount(new Currency(array('value' => $yearly_price_end, 'currency' => $cms['session']['client']['currency']['iso_code'])));
// Charge Models
$chargeModel = new ChargeModel();
$chargeModel->setType('SHIPPING')
->setAmount(new Currency(array('value' => 0, 'currency' => $cms['session']['client']['currency']['iso_code'])));
$paymentDefinition->setChargeModels(array($chargeModel));
$merchantPreferences = new MerchantPreferences();
// ReturnURL and CancelURL are not required and used when creating billing agreement with payment_method as "credit_card".
// However, it is generally a good idea to set these values, in case you plan to create billing agreements which accepts "paypal" as payment_method.
// This will keep your plan compatible with both the possible scenarios on how it is being used in agreement.
$merchantPreferences->setReturnUrl($ReturnUrl)
->setCancelUrl($CancelUrl)
->setAutoBillAmount("yes")
->setInitialFailAmountAction("CONTINUE")
->setMaxFailAttempts("0")
->setSetupFee(new Currency(array('value' => $setup_price_end, 'currency' => $cms['session']['client']['currency']['iso_code'])));
$plan->setPaymentDefinitions(array($paymentDefinition));
$plan->setMerchantPreferences($merchantPreferences);
// ### Create Plan
try {
$output = $plan->create($apiContext);
} catch (Exception $ex){
die($ex);
}
echo $output->getId().'<br />';
echo $output.'<br />';
Been working with paypal php sdk for some days now and my code stop working.
So i went back to basic and i am still getting the same damn error.
I am trying to create a plan for subscription but getting the following error:
"NotifyUrl is not a fully qualified URL"
I have no idea how to fix this as i dont use NotfifyUrl in my code?
Could be really nice if anyone had an idea how to fix this problem :)
Thanks
PayPal did a update to their API last night which has caused problem within their SDK.
They are sending back null values in their responses.
I MUST stress the error is not on sending the request to PayPal, but on processing their response.
BUG Report : https://github.com/paypal/PayPal-PHP-SDK/issues/1151
Pull Request : https://github.com/paypal/PayPal-PHP-SDK/pull/1152
Hope this helps, but their current SDK is throwing exceptions.
Use below simple fix.
Replace below function in vendor\paypal\rest-api-sdk-php\lib\PayPal\Api\MerchantPreferences.php
public function setNotifyUrl($notify_url)
{
if(!empty($notify_url)){
UrlValidator::validate($notify_url, "NotifyUrl");
}
$this->notify_url = $notify_url;
return $this;
}
If you get the same error for return_url/cancel_url, add the if condition as above.
Note: This is not a permanent solution, you can use this until getting the update from PayPal.
From the GitHub repo for the PayPal PHP SDK, I see that the error you mentioned is thrown when MerchantPreferences is not given a valid NotifyUrl. I see you're setting the CancelUrl and ReturnUrl, but not the NotifyUrl. You may simply need to set that as well, i.e.:
$NotifyUrl = (some url goes here)
$obj->setNotifyUrl($NotifyUrl);
Reason behind it!
error comes from.
vendor\paypal\rest-api-sdk-php\lib\PayPal\Validation\UrlValidator.php
line.
if (filter_var($url, FILTER_VALIDATE_URL) === false) {
throw new \InvalidArgumentException("$urlName is not a fully qualified URL");
}
FILTER_VALIDATE_URL: according to this php function.
INVALID URL: "http://cat_n.domain.net.in/"; // IT CONTAIN _ UNDERSCORE.
VALID URL: "http://cat-n.domain.net.in/"; it separated with - dash
here you can dump your url.
vendor\paypal\rest-api-sdk-php\lib\PayPal\Validation\UrlValidator.php
public static function validate($url, $urlName = null)
{
var_dump($url);
}
And then check this here: https://www.w3schools.com/PHP/phptryit.asp?filename=tryphp_func_validate_url
you can check here what character will reason for invalid.

Eventbrite API date range parameter for organizer_list_events

I need a way to search via the eventbrite api past events, by organizer, that are private, but I also need to be able to limit the date range. I have not found a viable solution for this search. I assume the organizer_list_events api would be the preferred method, but the request paramaters don't seem to allow for the date range, and I am getting FAR too many returns.
I'm having some similar issues I posted a question to get a response about parsing the timezone, here's the code I'm using to get the dates though and exclude any events before today (unfortunately like you said I'm still getting everything sent to me and paring things out client side)
Note this is an AngularJS control but the code is just using the EventBrite javascript API.
function EventCtrl($http, $scope)
{
$scope.events=[];
$scope.noEventsDisplay = "Loading events...";
Eventbrite({'app_key': "EVC36F6EQZZ4M5DL6S"}, function(eb){
// define a few parameters to pass to the API
// Options are listed here: http://developer.eventbrite.com/doc/organizers/organizer_list_events/
//3877641809
var options = {
'id' : "3588304527",
};
// provide a callback to display the response data:
eb.organizer_list_events( options, function( response ){
validEvents = [];
var now = new Date().getTime();
for(var i = 0; i<response.events.length; i++)
{
var sd = response.events[i].event.start_date;
var ed = response.events[i].event.end_date;
var parsedSD = sd.split(/[:-\s]/);
var parsedED = ed.split(/[:-\s]/);
var startDate = new Date(parsedSD[0], parsedSD[1]-1, parsedSD[2], parsedSD[3], parsedSD[4], parsedSD[5]);
var endDate = new Date(parsedED[0], parsedED[1]-1, parsedED[2], parsedED[3], parsedED[4], parsedED[5]);
if(endDate.getTime()<now)
continue;
response.events[i].event.formattedDate = date.toDateString();
validEvents.push(response.events[i])
}
if(validEvents.length == 0)
{
$scope.$apply(function(scope){scope.noEventsDisplay = "No upcoming events to display, please check back soon.";});
}
else
{
$scope.$apply(function(scope){scope.noEventsDisplay = "";});
}
$scope.$apply(function(scope){scope.events = validEvents;});
//$('.event_list').html(eb.utils.eventList( response, eb.utils.eventListRow ));
});
});
}

Pass through Magento Purchase Order number to Shipworks ; then add to Fedex Reference field

I use Shipworks 3 with Magento 1.5.1 and would like to pass the Purchase order NUMBER through. Right now the Payment Type comes through but I need the PO number so it can go on/print on the Packaking slip, invoice, AND Shipping label.
Here's a snippet from the shipworks.php. I'm guessing I just have to add to this section but not sure what to add.
Thank you for any help.
$payment = $order->getPayment();
// CC info
if ($secure)
{
$cc_num = $payment->getCcNumber();
}
else
{
$cc_num = $payment->getCcLast4();
if (!empty($cc_num))
{
$cc_num = '************'.$payment->getCcLast4();
}
}
$cc_year = sprintf('%02u%s', $payment->getCcExpMonth(), substr($payment->getCcExpYear(), 2));
writeStartTag("Payment");
writeElement("Method", Mage::helper('payment')->getMethodInstance($payment->getMethod())->getTitle());
writeStartTag("CreditCard");
writeElement("Type", $payment->getCcType());
writeElement("Owner", $payment->getCcOwner());
writeElement("Number", $cc_num);
writeElement("Expires", $cc_year);
writeCloseTag("CreditCard");
writeCloseTag("Payment");
I was able to use the following to get my po number to show up in the notes. This is what I used. hope it helps.
// CC info
if ($secure)
{
$cc_num = $payment->getCcNumber();
}
else
{
$cc_num = $payment->getCcLast4();
if (!empty($cc_num))
{
$cc_num = '************'.$payment->getCcLast4();
}
}
$cc_year = sprintf('%02u%s', $payment->getCcExpMonth(), substr($payment->getCcExpYear(), 2));
writeStartTag("Payment");
writeElement("Method", Mage::helper('payment')->getMethodInstance($payment->getMethod())->getTitle());
writeStartTag("CreditCard");
writeElement("Type", $payment->getCcType());
writeElement("Owner", $payment->getCcOwner());
writeElement("Number", $cc_num);
writeElement("Expires", $cc_year);
writeCloseTag("CreditCard");
writeCloseTag("Payment");
writeStartTag("Notes");
writeFullElement("Note", $payment->getPoNumber(),array("public" =>"true"));
writeCloseTag("Notes");
WriteOrderItems($order->getAllItems());
WriteOrderTotals($order);
Shipworks is very picky about the XML tags that it receives. You can't just add something to the response because it'll throw errors in the SW software when it tries to sync with your Magento store. You can add it by using an existing element that isn't currently being used. In our case, we weren't using Gift Messages, which get added to the response as Notes, so I re-purposed the Notes element to contain something else.
Look at the WriteOrder function (around line 396) and find this section:
if ($order->getGiftMessageId())
{
$message = Mage::helper('giftmessage/message')->getGiftMessage($order->getGiftMessageId());
$messageString = "Gift message for ". $message['recipient']. ": ". $message['message'];
writeStartTag("Notes");
writeFullElement("Note", $messageString, array("public" => "true"));
writeCloseTag("Notes");
}
Comment out this section and add something like this:
if ($order->getPoNumber())
{
writeStartTag("Notes");
writeFullElement("Note", $order->getPoNumber(), array("public" => "true"));
writeCloseTag("Notes");
}
NOTE: I don't know if $order->getPoNumber() actually works...this is just a sample of what you'll need to do