mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
Get store currency from service
This commit is contained in:
parent
7d219bbd14
commit
6d400c7bf3
3 changed files with 79 additions and 23 deletions
|
@ -220,7 +220,7 @@ return array(
|
||||||
return new CatalogProducts(
|
return new CatalogProducts(
|
||||||
$container->get( 'api.host' ),
|
$container->get( 'api.host' ),
|
||||||
$container->get( 'api.bearer' ),
|
$container->get( 'api.bearer' ),
|
||||||
$container->get('api.factory.product'),
|
$container->get( 'api.factory.product' ),
|
||||||
$container->get( 'woocommerce.logger.woocommerce' )
|
$container->get( 'woocommerce.logger.woocommerce' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -228,8 +228,8 @@ return array(
|
||||||
return new BillingPlans(
|
return new BillingPlans(
|
||||||
$container->get( 'api.host' ),
|
$container->get( 'api.host' ),
|
||||||
$container->get( 'api.bearer' ),
|
$container->get( 'api.bearer' ),
|
||||||
$container->get('api.factory.billing-cycle'),
|
$container->get( 'api.factory.billing-cycle' ),
|
||||||
$container->get('api.factory.plan'),
|
$container->get( 'api.factory.plan' ),
|
||||||
$container->get( 'woocommerce.logger.woocommerce' )
|
$container->get( 'woocommerce.logger.woocommerce' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -388,19 +388,19 @@ return array(
|
||||||
'api.factory.fraud-processor-response' => static function ( ContainerInterface $container ): FraudProcessorResponseFactory {
|
'api.factory.fraud-processor-response' => static function ( ContainerInterface $container ): FraudProcessorResponseFactory {
|
||||||
return new FraudProcessorResponseFactory();
|
return new FraudProcessorResponseFactory();
|
||||||
},
|
},
|
||||||
'api.factory.product' => static function(ContainerInterface $container): ProductFactory {
|
'api.factory.product' => static function( ContainerInterface $container ): ProductFactory {
|
||||||
return new ProductFactory();
|
return new ProductFactory();
|
||||||
},
|
},
|
||||||
'api.factory.billing-cycle' => static function(ContainerInterface $container): BillingCycleFactory {
|
'api.factory.billing-cycle' => static function( ContainerInterface $container ): BillingCycleFactory {
|
||||||
return new BillingCycleFactory();
|
return new BillingCycleFactory( $container->get( 'api.shop.currency' ) );
|
||||||
},
|
},
|
||||||
'api.factory.payment-preferences' => static function(ContainerInterface $container):PaymentPreferencesFactory {
|
'api.factory.payment-preferences' => static function( ContainerInterface $container ):PaymentPreferencesFactory {
|
||||||
return new PaymentPreferencesFactory();
|
return new PaymentPreferencesFactory( $container->get( 'api.shop.currency' ) );
|
||||||
},
|
},
|
||||||
'api.factory.plan' => static function(ContainerInterface $container): PlanFactory {
|
'api.factory.plan' => static function( ContainerInterface $container ): PlanFactory {
|
||||||
return new PlanFactory(
|
return new PlanFactory(
|
||||||
$container->get('api.factory.billing-cycle'),
|
$container->get( 'api.factory.billing-cycle' ),
|
||||||
$container->get('api.factory.payment-preferences')
|
$container->get( 'api.factory.payment-preferences' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'api.helpers.dccapplies' => static function ( ContainerInterface $container ) : DccApplies {
|
'api.helpers.dccapplies' => static function ( ContainerInterface $container ) : DccApplies {
|
||||||
|
|
|
@ -15,25 +15,53 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\BillingCycle;
|
||||||
|
|
||||||
class BillingCycleFactory {
|
class BillingCycleFactory {
|
||||||
|
|
||||||
public function from_wc_product(WC_Product $product): BillingCycle {
|
/**
|
||||||
|
* The currency.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $currency;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The currency.
|
||||||
|
*
|
||||||
|
* @param string $currency
|
||||||
|
*/
|
||||||
|
public function __construct( string $currency ) {
|
||||||
|
$this->currency = $currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a BillingCycle object from the given WC product.
|
||||||
|
*
|
||||||
|
* @param WC_Product $product WC product.
|
||||||
|
* @return BillingCycle
|
||||||
|
*/
|
||||||
|
public function from_wc_product( WC_Product $product ): BillingCycle {
|
||||||
return new BillingCycle(
|
return new BillingCycle(
|
||||||
array(
|
array(
|
||||||
'interval_unit' => $product->get_meta('_subscription_period'),
|
'interval_unit' => $product->get_meta( '_subscription_period' ),
|
||||||
'interval_count' => $product->get_meta('_subscription_period_interval'),
|
'interval_count' => $product->get_meta( '_subscription_period_interval' ),
|
||||||
),
|
),
|
||||||
1,
|
1,
|
||||||
'REGULAR',
|
'REGULAR',
|
||||||
array(
|
array(
|
||||||
'fixed_price' => array(
|
'fixed_price' => array(
|
||||||
'value' => $product->get_meta('_subscription_price'),
|
'value' => $product->get_meta( '_subscription_price' ),
|
||||||
'currency_code' => 'USD',
|
'currency_code' => $this->currency,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
(int)$product->get_meta('_subscription_length')
|
(int) $product->get_meta( '_subscription_length' )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function from_paypal_response(stdClass $data): BillingCycle {
|
/**
|
||||||
|
* Returns a BillingCycle object based off a PayPal response.
|
||||||
|
*
|
||||||
|
* @param stdClass $data the data.
|
||||||
|
* @return BillingCycle
|
||||||
|
*/
|
||||||
|
public function from_paypal_response( stdClass $data ): BillingCycle {
|
||||||
return new BillingCycle(
|
return new BillingCycle(
|
||||||
array(
|
array(
|
||||||
'interval_unit' => $data->frequency->interval_unit,
|
'interval_unit' => $data->frequency->interval_unit,
|
||||||
|
|
|
@ -15,16 +15,44 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentPreferences;
|
||||||
|
|
||||||
class PaymentPreferencesFactory {
|
class PaymentPreferencesFactory {
|
||||||
|
|
||||||
public function from_wc_product(WC_Product $product):PaymentPreferences {
|
/**
|
||||||
|
* The currency.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $currency;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PaymentPreferencesFactory constructor.
|
||||||
|
*
|
||||||
|
* @param string $currency The currency.
|
||||||
|
*/
|
||||||
|
public function __construct( string $currency ) {
|
||||||
|
$this->currency = $currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a PaymentPreferences object from the given WC product.
|
||||||
|
*
|
||||||
|
* @param WC_Product $product WC product.
|
||||||
|
* @return PaymentPreferences
|
||||||
|
*/
|
||||||
|
public function from_wc_product( WC_Product $product ):PaymentPreferences {
|
||||||
return new PaymentPreferences(
|
return new PaymentPreferences(
|
||||||
array(
|
array(
|
||||||
'value' => $product->get_meta( '_subscription_sign_up_fee' ) ?: '0',
|
'value' => $product->get_meta( '_subscription_sign_up_fee' ) ?: '0',
|
||||||
'currency_code' => 'USD',
|
'currency_code' => $this->currency,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function from_paypal_response(stdClass $data) {
|
/**
|
||||||
|
* Returns a PaymentPreferences object based off a PayPal response.
|
||||||
|
*
|
||||||
|
* @param stdClass $data The data.
|
||||||
|
* @return PaymentPreferences
|
||||||
|
*/
|
||||||
|
public function from_paypal_response( stdClass $data ) {
|
||||||
return new PaymentPreferences(
|
return new PaymentPreferences(
|
||||||
array(
|
array(
|
||||||
'value' => $data->setup_fee->value,
|
'value' => $data->setup_fee->value,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue