Windows command line PHP can not find OpenSSL after installing MAMP

You have just installed MAMP and set up your project and ran composer udpate and you see the annoying

The openssl extension is required for SSL/TLS protection but is not available. If you can not enable the openssl extension, you can disable this error, at your own risk, by
setting the 'disable-tls' option to true.

Then you check your config D:\MAMP\conf\php7.2.10 to find that you already have enabled openssl

When you check your php config in browser you also see that it is there. http://localhost:8081/MAMP/index.php?page=phpinfo&language=English

So, why when you run composer update php can not find this?

Solution

By default, the php.exe file located in D:\MAMP\bin\php\php7.2.10 looks for a php.ini in the same folder and in MAMP it can not find it. So, it loads some php.ini where the OpenSSL is not enabled.

You can just copy your correct php.ini and put in the same directory of your php executable i.e. D:\MAMP\bin\php\php7.2.10

And that is all you need to do.

Making a Payment Using Paypal Payout

What you need

First and foremost make sure you have the following

1. Login to Developer Dashboard: https://developer.paypal.com and create a PayPal Sandbox account and add funds. If you want to pay others from your business account then Create a ‘BUSINESS’ type user. Otherwise, if you want to purchase as a shopper you should create ‘PERSONAL’ type user.

2019-09-23 21_22_05-Activity - PayPal
2019-09-23 20_53_10-Sandbox accounts _ PayPal Developer

2. Create an app for the Sandbox Account. You should get CLIENT_ID and SECRET for this app which will be required for authenticating API calls later in your application. Make sure the app has the necessary permission.

2019-09-23 21_02_37-Summary - PayPal

3. Log-in to Sandbox https://www.sandbox.paypal.com and make sure the user/account has sufficient fund in the currencies you want to do the transaction. Note – If you need multiple currencies then you must have sufficient fund for in all the currencies.

2019-09-23 21_19_51-Edit Applications - PayPal Developer

Now you have everything that you need to move on to the coding part. Here is the list of things that you should have by now.

  1. Developer dashboard login
  2. Sandbox account
  3. Sandbox App CLIENT_ID and SECRET

Code

"paypal/rest-api-sdk-php": "*"

2. Update config/paypal.php and include the Sandbox App CLIENT_ID and SECRET. A smart approach is to create a couple of  .env vars

PAYPAL_CLIENT_ID='AVeNF_OsmXeg1TNxoUgL4BXDYZrploB0-G_NinSxvIY4Oi6SHOaJHYtok7n3kx_0twJBuz'
PAYPAL_SECRET='EEvSwYJQaDKH1cy6DOuhSw4hWwxZZCZKKhtwdL0BCCEBCucYtyzxS3h2x5foa9PJMdmoav'
<?php

namespace App\Classes;

use App\Invoice;
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;

class Paypal
{
    private $_api_context;

    public function __construct()
    {
        // setup PayPal api context
        $this->_api_context = new ApiContext(new OAuthTokenCredential(conf('paypal.client_id'), conf('paypal.secret')));
        $this->_api_context->setConfig(conf('paypal.settings'));

    }

    public function pay(Invoice $invoice)
    {


        $payouts = new \PayPal\Api\Payout();

        /*
         * {
                    "sender_batch_header":{
                        "sender_batch_id":"2014021801",
                        "email_subject":"You have a Payout!"
                    },
                    "items":[
                        {
                            "recipient_type":"EMAIL",
                            "amount":{
                                "value":"1.0",
                                "currency":"USD"
                            },
                            "note":"Thanks for your patronage!",
                            "sender_item_id":"2014031400023",
                            "receiver":"shirt-supplier-one@mail.com"
                        }
                    ]
                }
         */

        $senderBatchHeader = new \PayPal\Api\PayoutSenderBatchHeader();
        $senderBatchHeader->setSenderBatchId($invoice->code)
            ->setEmailSubject("You have a Payout!");

        $senderItem = new \PayPal\Api\PayoutItem();
        $senderItem->setRecipientType('Email')
            ->setNote('Thanks for your patronage!')
            ->setReceiver('shirt-supplier-one@gmail.com')
            ->setSenderItemId("2014031400023")
            ->setAmount(new \PayPal\Api\Currency('{
                        "value":"1.0",
                        "currency":"USD"
                    }'));

        $payouts->setSenderBatchHeader($senderBatchHeader)
            ->addItem($senderItem);

        // $request = clone $payouts;

        try {
            // $output = $payouts->createSynchronous($this->_api_context);
            $output = $payouts->create(array('sync_mode' => 'false'), $this->_api_context);
        } catch (\Exception $e) {
            return setError($e->getMessage());
        }
        return $output;
    }
}

Additional resources

Smartgit – still run it after trial expires

Smartgit is one of the best git tool available. I have used a few but smartgit is really cool. However your license as a non-commercial free user expires in 2-3 months. This is how you can get it working again. Someone has shared this in stackover flow.

To alter the license. First, go to

Windows: %APPDATA%\syntevo\SmartGit\<main-smartgit-version>

OS X: ~/Library/Preferences/SmartGit/<main-smartgit-version>

Unix/Linux: ~/.smartgit/<main-smartgit-version>

and remove the file settings.xml.

If you have updated many times, you may need to remove the updates folder as well.

It helped me on Windows, hope it helps you on other systems as well.