mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +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
|
@ -1,5 +1,6 @@
|
|||
import onApprove from '../OnApproveHandler/onApproveForContinue.js';
|
||||
import {payerData} from "../Helper/PayerData";
|
||||
import {PaymentMethods} from "../Helper/CheckoutMethodState";
|
||||
|
||||
class CartActionHandler {
|
||||
|
||||
|
@ -18,6 +19,7 @@ class CartActionHandler {
|
|||
body: JSON.stringify({
|
||||
nonce: this.config.ajax.create_order.nonce,
|
||||
purchase_units: [],
|
||||
payment_method: PaymentMethods.PAYPAL,
|
||||
bn_code:bnCode,
|
||||
payer,
|
||||
context:this.config.context
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import onApprove from '../OnApproveHandler/onApproveForPayNow.js';
|
||||
import {payerData} from "../Helper/PayerData";
|
||||
import {getCurrentPaymentMethod} from "../Helper/CheckoutMethodState";
|
||||
|
||||
class CheckoutActionHandler {
|
||||
|
||||
|
@ -31,6 +32,7 @@ class CheckoutActionHandler {
|
|||
bn_code:bnCode,
|
||||
context:this.config.context,
|
||||
order_id:this.config.order_id,
|
||||
payment_method: getCurrentPaymentMethod(),
|
||||
form:formValues,
|
||||
createaccount: createaccount
|
||||
})
|
||||
|
|
|
@ -2,6 +2,7 @@ import ButtonsToggleListener from '../Helper/ButtonsToggleListener';
|
|||
import Product from '../Entity/Product';
|
||||
import onApprove from '../OnApproveHandler/onApproveForContinue';
|
||||
import {payerData} from "../Helper/PayerData";
|
||||
import {PaymentMethods} from "../Helper/CheckoutMethodState";
|
||||
|
||||
class SingleProductActionHandler {
|
||||
|
||||
|
@ -84,6 +85,7 @@ class SingleProductActionHandler {
|
|||
purchase_units,
|
||||
payer,
|
||||
bn_code:bnCode,
|
||||
payment_method: PaymentMethods.PAYPAL,
|
||||
context:this.config.context
|
||||
})
|
||||
}).then(function (res) {
|
||||
|
|
|
@ -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