Updated Stripe Profile
added attribute send_email_receipt to let end user choose if should send the stripe email or not. Change-Id: I88446e237e59d7f1dfdef9e5a55d20f2fa004c0c Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
parent
7f3cc9e17f
commit
c14491545c
@ -42,6 +42,7 @@ final class PaymentGatewayProfileValidationRulesFactory
|
||||
'live_publishable_key' => 'required_with:live_secret_key|string',
|
||||
'test_secret_key' => 'required_with:test_mode_enabled|string',
|
||||
'test_publishable_key' => 'required_with:test_secret_key|string',
|
||||
'send_email_receipt' => 'sometimes|boolean',
|
||||
]);
|
||||
}
|
||||
return $rules;
|
||||
@ -60,6 +61,7 @@ final class PaymentGatewayProfileValidationRulesFactory
|
||||
'live_publishable_key' => 'required_with:live_secret_key|string',
|
||||
'test_secret_key' => 'required_with:test_mode_enabled|string',
|
||||
'test_publishable_key' => 'required_with:test_secret_key|string',
|
||||
'send_email_receipt' => 'sometimes|boolean',
|
||||
]);
|
||||
}
|
||||
return $rules;
|
||||
|
@ -20,6 +20,7 @@ class StripePaymentProfileSerializer extends PaymentGatewayProfileSerializer
|
||||
{
|
||||
protected static $array_mappings = [
|
||||
'TestModeEnabled' => 'test_mode_enabled:json_boolean',
|
||||
'SendEmailReceipt' => 'send_email_receipt:json_boolean',
|
||||
'LivePublishableKey' => 'live_publishable_key:json_string',
|
||||
'TestPublishableKey' => 'test_publishable_key:json_string',
|
||||
];
|
||||
|
@ -78,6 +78,9 @@ final class PaymentGatewayProfileFactory
|
||||
if (isset($params['active']))
|
||||
boolval(['active']) == true ? $profile->activate() : $profile->disable();
|
||||
|
||||
if (isset($params['send_email_receipt']))
|
||||
$profile->setSendEmailReceipt(boolval($params['send_email_receipt']));
|
||||
|
||||
return $profile;
|
||||
}
|
||||
}
|
@ -80,6 +80,12 @@ class StripePaymentProfile extends PaymentGatewayProfile
|
||||
*/
|
||||
protected $test_webhook_secret_key;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="SendEmailReceipt", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $send_email_receipt;
|
||||
|
||||
/**
|
||||
* StripePaymentProfile constructor.
|
||||
*/
|
||||
@ -87,6 +93,7 @@ class StripePaymentProfile extends PaymentGatewayProfile
|
||||
{
|
||||
parent::__construct();
|
||||
$this->test_mode_enabled = true;
|
||||
$this->send_email_receipt = false;
|
||||
$this->provider = IPaymentConstants::ProviderStripe;
|
||||
$this->live_webhook_id = '';
|
||||
$this->live_webhook_secret_key = '';
|
||||
@ -267,11 +274,14 @@ class StripePaymentProfile extends PaymentGatewayProfile
|
||||
private function createTestConfiguration(): array
|
||||
{
|
||||
$params = [
|
||||
'secret_key' => $this->test_secret_key
|
||||
'secret_key' => $this->test_secret_key,
|
||||
'send_email_receipt' => $this->send_email_receipt
|
||||
];
|
||||
|
||||
if (!empty($this->test_webhook_secret_key)) {
|
||||
$params['webhook_secret_key'] = $this->test_webhook_secret_key;
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
@ -281,8 +291,10 @@ class StripePaymentProfile extends PaymentGatewayProfile
|
||||
private function createLiveConfiguration(): array
|
||||
{
|
||||
$params = [
|
||||
'secret_key' => $this->live_secret_key
|
||||
'secret_key' => $this->live_secret_key,
|
||||
'send_email_receipt' => $this->send_email_receipt
|
||||
];
|
||||
|
||||
if (!empty($this->live_webhook_secret_key)) {
|
||||
$params['webhook_secret_key'] = $this->live_webhook_secret_key;
|
||||
}
|
||||
@ -497,4 +509,21 @@ class StripePaymentProfile extends PaymentGatewayProfile
|
||||
Log::debug(sprintf("StripePaymentProfile::setTestWebhookSecretKey %s", $test_webhook_secret_key));
|
||||
$this->test_webhook_secret_key = $test_webhook_secret_key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isSendEmailReceipt(): bool
|
||||
{
|
||||
return $this->send_email_receipt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $send_email_receipt
|
||||
*/
|
||||
public function setSendEmailReceipt(bool $send_email_receipt): void
|
||||
{
|
||||
$this->send_email_receipt = $send_email_receipt;
|
||||
}
|
||||
|
||||
}
|
@ -4429,6 +4429,7 @@ SQL;
|
||||
return $payment_profile->buildPaymentGatewayApi();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return ArrayCollection|\Doctrine\Common\Collections\Collection
|
||||
*/
|
||||
@ -4451,6 +4452,7 @@ SQL;
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where(Criteria::expr()->eq('active', true));
|
||||
$criteria->andWhere(Criteria::expr()->eq('application_type', trim($application_type)));
|
||||
|
||||
$payment_profile = $this->payment_profiles->matching($criteria)->first();
|
||||
return (!$payment_profile) ? null : $payment_profile;
|
||||
}
|
||||
|
@ -44,6 +44,11 @@ final class StripeApi implements IPaymentGatewayAPI
|
||||
*/
|
||||
private $webhook_secret_key;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $send_email_receipt;
|
||||
|
||||
/**
|
||||
* StripeApi constructor.
|
||||
* @param array $config
|
||||
@ -52,6 +57,9 @@ final class StripeApi implements IPaymentGatewayAPI
|
||||
{
|
||||
$this->secret_key = $config['secret_key'] ?? null;
|
||||
$this->webhook_secret_key = $config['webhook_secret_key'] ?? null;
|
||||
$this->send_email_receipt = false;
|
||||
if(isset($config['send_email_receipt']))
|
||||
$this->send_email_receipt = boolval($config['send_email_receipt']);
|
||||
|
||||
Log::debug
|
||||
(
|
||||
@ -102,7 +110,10 @@ final class StripeApi implements IPaymentGatewayAPI
|
||||
'payment_method_types' => ['card'],
|
||||
];
|
||||
|
||||
if (isset($payload['receipt_email'])) {
|
||||
// check setting to send stripe invoice
|
||||
// @see https://stripe.com/docs/receipts
|
||||
if (isset($payload['receipt_email']) && $this->send_email_receipt) {
|
||||
Log::debug(sprintf("StripeApi::generatePayment setting receipt_email to %s", $payload['receipt_email']));
|
||||
$request['receipt_email'] = trim($payload['receipt_email']);
|
||||
}
|
||||
|
||||
@ -110,8 +121,10 @@ final class StripeApi implements IPaymentGatewayAPI
|
||||
$request['metadata'] = $payload['metadata'];
|
||||
}
|
||||
|
||||
$intent = PaymentIntent::create($request);
|
||||
Log::debug(sprintf("StripeApi::generatePayment creating payment intent %s", json_encode($request)));
|
||||
|
||||
$intent = PaymentIntent::create($request);
|
||||
Log::debug(sprintf("StripeApi::generatePayment intent id %s", $intent->id));
|
||||
return [
|
||||
'client_token' => $intent->client_secret,
|
||||
'cart_id' => $intent->id,
|
||||
|
@ -1,12 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Migrations\Model;
|
||||
|
||||
<?php namespace Database\Migrations\Model;
|
||||
/**
|
||||
* Copyright 2020 OpenStack Foundation
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema as Schema;
|
||||
use LaravelDoctrine\Migrations\Schema\Builder;
|
||||
use LaravelDoctrine\Migrations\Schema\Table;
|
||||
|
||||
/**
|
||||
* Class Version20200904155247
|
||||
* @package Database\Migrations\Model
|
||||
*/
|
||||
class Version20200904155247 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
|
@ -1,10 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Migrations\Model;
|
||||
|
||||
<?php namespace Database\Migrations\Model;
|
||||
/**
|
||||
* Copyright 2020 OpenStack Foundation
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema as Schema;
|
||||
|
||||
/**
|
||||
* Class Version20200910184756
|
||||
* @package Database\Migrations\Model
|
||||
*/
|
||||
class Version20200910184756 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
|
49
database/migrations/model/Version20200924123949.php
Normal file
49
database/migrations/model/Version20200924123949.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php namespace Database\Migrations\Model;
|
||||
/**
|
||||
* Copyright 2020 OpenStack Foundation
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema as Schema;
|
||||
use LaravelDoctrine\Migrations\Schema\Builder;
|
||||
use LaravelDoctrine\Migrations\Schema\Table;
|
||||
/**
|
||||
* Class Version20200924123949
|
||||
* @package Database\Migrations\Model
|
||||
*/
|
||||
class Version20200924123949 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
$builder = new Builder($schema);
|
||||
if($schema->hasTable("StripePaymentProfile") && !$builder->hasColumn("StripePaymentProfile","SendEmailReceipt") ) {
|
||||
$builder->table('StripePaymentProfile', function (Table $table) {
|
||||
$table->boolean('SendEmailReceipt')->setNotnull(true)->setDefault(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function down(Schema $schema)
|
||||
{
|
||||
$builder = new Builder($schema);
|
||||
if($schema->hasTable("StripePaymentProfile") && $builder->hasColumn("StripePaymentProfile","SendEmailReceipt") ) {
|
||||
$builder->table('StripePaymentProfile', function (Table $table) {
|
||||
$table->dropColumn('SendEmailReceipt');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user