if paypal plan has “inactive” status? - paypal

Working with Update Plan API
http://paypal.github.io/PayPal-PHP-SDK/sample/doc/billing/UpdatePlan.html
I did not find if plan has “inactive” state and which key have I to use for it?
I made :
$value = new PayPalModel('{
"state":"INACTIVE"
}');
But got error :
Requested state change is invalid.
1) How valid?
2) If in my developer's account there is a page where I can see all my plans and work with them in my developer's account ?
Thanks!

Code taken from:
https://github.com/paypal/PayPal-PHP-SDK/blob/master/lib/PayPal/Api/BankAccount.php
The BankAccount API extends PayPalModel and uses $state on the following line: 392
Here is the array:
/**
* State of this funding instrument.
* Valid Values: ["ACTIVE", "INACTIVE", "DELETED"]
*
* #param string $state
*
* #return $this
*/
public function setState($state)
{
$this->state = $state;
return $this;
}
From this PayPal Rest API - Update Billing Plan Return URL answer it might appear that you already have agreements attached to your plan so therefore you cannot make it INACTIVE.

Related

How to validate use entered phone number using slots in botpress?

I am experimenting on botpress slots . There is the new option called as slot which will validate the user input . However I am not able to find resources which will validate the user input.
The bot must validate the use input as a phone number using slot feature or any other without use of external api ?
Is this possible ?
for example:
If the user inputs a valide phone number the flow will proceed.
else if use enters invalid phone number the flow will ask to re enter a valid phone number.
I have tried multiple things but had no luck finding the proper documentation/ tutorial regarding it.
I think you can use a custom action to achieve this. A custom action for validating mobile number may look like:
const baseMessage = {
type: 'text',
markdown: false
}
/**
* check if phone number is valid
* #title validate phone number
* #category Validation
* #author Your name
* #param {string} phone - phone number
*/
const validateNumber = async phone => {
var phoneRegex = /^\d{10}$/
if (phone.match(phoneRegex)) {
temp.phone_validation = 'success'
} else {
temp.phone_validation = 'error'
}
}
return validateNumber(args.phone)
You can call the custom action in your validation flow and redirect user accordingly

Cloudflare Worker template script error - country redirect

I grabbed example script from the Cloudflare GitHub worker example page for a simple country redirect. It fails and I don't know why? (I am not particularly strong in code stuff).
Error is:
Script modified; context reset. worker.js:17 Uncaught TypeError: Cannot read properties of undefined (reading 'country')
at redirect (worker.js:17)
at worker.js:28 redirect # worker.js:17 (anonymous) # worker.js:28 Uncaught (in response) TypeError: Cannot read properties of undefined (reading 'country')
The template code is:
/**
* A map of the URLs to redirect to
* #param {Object} countryMap
*/
const countryMap = {
US: "https://example.com/us",
EU: "https://eu.example.com/",
}
/**
* Returns a redirect determined by the country code
* #param {Request} request
*/
function redirect(request) {
// Use the cf object to obtain the country of the request
// more on the cf object: https://developers.cloudflare.com/workers/runtime-apis/request#incomingrequestcfproperties
const country = request.cf.country
if (country != null && country in countryMap) {
const url = countryMap[country]
return Response.redirect(url)
} else {
return fetch(request)
}
}
addEventListener("fetch", event => {
event.respondWith(redirect(event.request))
})
From
https://github.com/cloudflare/cloudflare-docs/blob/production/products/workers/src/content/examples/country-code-redirect.md
Does anyone have advice on this? This is being run on the Cloudflare Workers system.
This is a known problem with the Worokers preview. request.cf is always undefined when using the embedded preview next to the editor. If you use wrangler dev to test your code instead, it will work correctly there, and it will also work once deployed.

Dingo Api response->created | location and content example

I am creating API with Laravel 5.2 and Dingo API package. When a user is created, I want to return 201 response with the new $user->id.
My Code
return $this->response->created();
As per Dingo documentatio, I can provide a location and $content as parameters in the created() function.
My question is, what location information I need to return here and I tried to set my new user as $content, but it's not working or I am not sure what to expect.
Can someone please explain this created() function?
What this does is set the Location header, as seen in the source:
/**
* Respond with a created response and associate a location if provided.
*
* #param null|string $location
*
* #return \Dingo\Api\Http\Response
*/
public function created($location = null, $content = null)
{
$response = new Response($content);
$response->setStatusCode(201);
if (! is_null($location)) {
$response->header('Location', $location);
}
return $response;
}
So, in your example since you're creating a new user, you might send the users profile page as the location, something like:
return $this->response->created('/users/123');
As for the content, as you can see in the function this sets the content on the return. In your case, it would probably be a json string with the new user information, something like:
return $this->response->created('/users/123', $user); // laravel should automatically json_encode the user object

CakePHP HTTPS Secure payment form

Using CakePHP 1.3 we have a booking system for hotel rooms. A check-availability form should bring the user to a secure payment page (https://secure.domain.com/bookings/payment). After making the payment, the user gets a confirmation page (secured is also ok), but from here, any links in our header/footer should take the user back to the non-secured domain (http://domain.com).
Currently we have our SSL UCC Cert set up for the domains https://secure.domain.com and https://domain.com. We have also hard coded the check-availability form to run the action https://secure.domain.com/bookings/payment. Thus, we can get the user to get in to the HTTPS secured area, but not back out unless we hard code all our links in that section.
Cake's security component is quite confusing and thus I am looking for the best solution to make this happen.
Can Cake's Security component be used for HTTPS payment pages, make life easier, and keep the code more CakePHP standardized? Any other suggestions?
this is a pretty good way to go: http://techno-geeks.org/2009/03/using-the-security-component-in-cakephp-for-ssl/ so you won't even have to hard code anything.
I used the example from http://techno-geeks.org/2009/03/using-the-security-component-in-cakephp-for-ssl/ but found it problematic. I ended up adding the following to my app_controller.php.
The code below redirects HTTPS to www.example.com and HTTP to example.com. If a user is logged in (see $loggedUser), it forces HTTPS for every connection.
// Pages requiring a secure connection.
$secureItems = array();
// beforeFilter
function beforeFilter() {
// Your logic...
$this->__checkSSL();
}
/**
* Check SSL connection.
*/
function __checkSSL() {
/** Make sure we are secure when we need to be! **/
if (empty($this->loggedUser)) {
if (in_array($this->action, $this->secureItems) && !env('HTTPS')) {
$this->__forceSSL();
}
if (!in_array($this->action, $this->secureItems) && env('HTTPS')) {
$this->__unforceSSL();
}
} else {
// Always force HTTPS if user is logged in.
if (!env('HTTPS')) {
$this->__forceSSL();
}
}
}
/**
* Redirect to a secure connection
* #return unknown_type
*/
function __forceSSL() {
if (strstr(env('SERVER_NAME'), 'www.')) {
$this->redirect('https://' . env('SERVER_NAME') . $this->here);
} else {
$this->redirect('https://www.' . env('SERVER_NAME') . $this->here);
}
}
/**
* Redirect to an unsecure connection
* #return unknown_type
*/
function __unforceSSL() {
if (strstr(env('SERVER_NAME'), 'www.')) {
$server = substr(env('SERVER_NAME'), 4);
$this->redirect('http://' . $server . $this->here);
} else {
$this->redirect('http://' . env('SERVER_NAME') . $this->here);
}
}

zend acl multiple access lists/levels

I'm building a portal where user and companies can join. Users can either be independent or working under a company. There is some basic access which is available to all users regardless of their type (independent or associated with a company). There is some more features which are available to independent users, but if a user is under the company, the company manager will be able to allow/disallow their access to specific features. How can I manage this using Zend_Acl?
You're ACL's can have conditions.
In the file where I declare my ACLs (a plugin by the way), I have the following declaration. The Acl_AdminCanAccessUsers is a Zend_Acl_Assert_Interface and will either return TRUE or FALSE. Here I am also passing the Request Object to the constructor.
// Complex function to see if the current user can create/edit the desired user account.
$acl->allow('client', 'user', array('edit','create'), new Acl_AdminCanAccessUsers($this->_request));
Now let's take a look at Acl_AdminCanAccessUsers
<?php
class Acl_AdminCanAccessUsers implements Zend_Acl_Assert_Interface
{
public function __construct($request) {
$this->request = $request;
}
public function assert(Zend_Acl $acl,
Zend_Acl_Role_Interface $role = null,
Zend_Acl_Resource_Interface $resource = null,
$privilege = null)
{
/**
* Can only test when trying to edit a user account
*/
if ("edit" != $privilege) {
return TRUE;
}
$identity = Zend_Auth::getInstance()->getIdentity();
/**
* Get the id from the URL request
*/
$id = $this->request->getParam('id');
/**
* Get user account from DB
*/
$user = Doctrine_Core::getTable('User')->find($id);
// Are they editing their own account? Give them a pass
if ($identity->user_id == $user->user_id) {
return TRUE;
}
// If they don't have the isAdmin flag set to yes on their account
// Then we'll just deny them immediately
if ($identity->isAdmin) {
return TRUE;
}
return FALSE;
}
}
As you can see here we are checking the db for the user record and comparing it to a parameter that is requested or checking if they have isAdmin flag set in their Zend_Auth identity. You can do lots of conditional checking for your ACLs if there is more to access than just a role, resource, and privilege.
Happy Coding!