mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Handle free trial sub for cards
authorize 1$ and void
This commit is contained in:
parent
ade7107227
commit
f5a472673b
16 changed files with 288 additions and 69 deletions
|
@ -13,6 +13,9 @@ use Exception;
|
|||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Address;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Amount;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\AmountBreakdown;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PayerName;
|
||||
|
@ -25,7 +28,9 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Repository\CartRepository;
|
||||
use WooCommerce\PayPalCommerce\Button\Helper\EarlyOrderHandler;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\Subscription\FreeTrialHandlerTrait;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
/**
|
||||
|
@ -33,6 +38,8 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
|||
*/
|
||||
class CreateOrderEndpoint implements EndpointInterface {
|
||||
|
||||
use FreeTrialHandlerTrait;
|
||||
|
||||
const ENDPOINT = 'ppc-create-order';
|
||||
|
||||
/**
|
||||
|
@ -177,6 +184,7 @@ class CreateOrderEndpoint implements EndpointInterface {
|
|||
try {
|
||||
$data = $this->request_data->read_request( $this->nonce() );
|
||||
$this->parsed_request_data = $data;
|
||||
$payment_method = $data['payment_method'] ?? '';
|
||||
$wc_order = null;
|
||||
if ( 'pay-now' === $data['context'] ) {
|
||||
$wc_order = wc_get_order( (int) $data['order_id'] );
|
||||
|
@ -193,6 +201,16 @@ class CreateOrderEndpoint implements EndpointInterface {
|
|||
$this->purchase_units = array( $this->purchase_unit_factory->from_wc_order( $wc_order ) );
|
||||
} else {
|
||||
$this->purchase_units = $this->cart_repository->all();
|
||||
|
||||
// The cart does not have any info about payment method, so we must handle free trial here.
|
||||
if ( CreditCardGateway::ID === $payment_method && $this->is_free_trial_cart() ) {
|
||||
$this->purchase_units[0]->set_amount(
|
||||
new Amount(
|
||||
new Money( 1.0, $this->purchase_units[0]->amount()->currency_code() ),
|
||||
$this->purchase_units[0]->amount()->breakdown()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->set_bn_code( $data );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue