-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathPartnerReferralsData.php
More file actions
158 lines (138 loc) · 4.78 KB
/
Copy pathPartnerReferralsData.php
File metadata and controls
158 lines (138 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/**
* The partner referrals data object.
*
* @package WooCommerce\PayPalCommerce\ApiClient\Repository
*/
declare( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\ApiClient\Repository;
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
use WooCommerce\PayPalCommerce\Settings\Data\Definition\FeaturesDefinition;
class PartnerReferralsData {
/**
* The DCC Applies Helper object.
*
* @deprecated Deprecates with the new UI. In this class, the products are
* always explicit, and should not be deducted from the
* DccApplies state at this point.
* Remove this with the #legacy-ui code.
* @var DccApplies
*/
private DccApplies $dcc_applies;
protected FeaturesDefinition $features_definition;
public function __construct( DccApplies $dcc_applies, FeaturesDefinition $features_definition ) {
$this->dcc_applies = $dcc_applies; // @phpstan-ignore property.deprecated
$this->features_definition = $features_definition;
}
/**
* Returns a nonce.
*
* @return string
*/
public function nonce(): string {
return 'a1233wtergfsdt4365tzrshgfbaewa36AGa1233wtergfsdt4365tzrshgfbaewa36AG';
}
/**
* Returns the data.
*
* @param string[] $products The list of products to use ('PPCP', 'EXPRESS_CHECKOUT').
* Default is based on DCC availability.
* @param string $onboarding_token A security token to finalize the onboarding process.
* @param bool $use_subscriptions If the merchant requires subscription features.
* @param bool $use_card_payments If the merchant wants to process credit card payments.
* @return array
*/
public function data(
array $products = array(),
string $onboarding_token = '',
?bool $use_subscriptions = null,
bool $use_card_payments = true
): array {
$in_acdc_country = $this->dcc_applies->for_country_currency(); // @phpstan-ignore property.deprecated
if ( ! $products ) {
$products = array(
$in_acdc_country ? 'PPCP' : 'EXPRESS_CHECKOUT',
);
}
/**
* Filter the return-URL, which is called at the end of the OAuth onboarding
* process, when the merchant clicks the "Return to your shop" button.
*/
$return_url = apply_filters(
'woocommerce_paypal_payments_partner_config_override_return_url',
admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway' )
);
/**
* Filter the label of the "Return to your shop" button.
* It's displayed on the very last page of the onboarding popup.
*/
$return_url_label = apply_filters(
'woocommerce_paypal_payments_partner_config_override_return_url_description',
__( 'Return to your shop.', 'woocommerce-paypal-payments' )
);
$capabilities = array();
$first_party_features = array(
'PAYMENT',
'REFUND',
'ADVANCED_TRANSACTIONS_SEARCH',
'TRACKING_SHIPMENT_READWRITE',
);
if ( $in_acdc_country ) {
$products = array( 'PPCP', 'ADVANCED_VAULTING' );
$capabilities[] = 'PAYPAL_WALLET_VAULTING_ADVANCED';
}
$first_party_features[] = 'BILLING_AGREEMENT';
if ( $use_card_payments !== false ) {
$first_party_features[] = 'VAULT';
$first_party_features[] = 'FUTURE_PAYMENT';
}
if ( $this->features_definition->is_feature_eligible( FeaturesDefinition::FEATURE_PAY_UPON_INVOICE ) ) {
$products[] = 'PAYMENT_METHODS';
$capabilities[] = 'PAY_UPON_INVOICE';
}
$payload = array(
'partner_config_override' => array(
'return_url' => $return_url,
'return_url_description' => $return_url_label,
'show_add_credit_card' => $use_card_payments,
),
'products' => $products,
'capabilities' => $capabilities,
'legal_consents' => array(
array(
'type' => 'SHARE_DATA_CONSENT',
'granted' => true,
),
),
'operations' => array(
array(
'operation' => 'API_INTEGRATION',
'api_integration_preference' => array(
'rest_api_integration' => array(
'integration_method' => 'PAYPAL',
'integration_type' => 'FIRST_PARTY',
'first_party_details' => array(
'features' => $first_party_features,
'seller_nonce' => $this->nonce(),
),
),
),
),
),
);
/**
* Filter the final partners referrals data collection.
*/
$payload = apply_filters( 'ppcp_partner_referrals_data', $payload );
// An empty array is not permitted.
if ( isset( $payload['capabilities'] ) && ! $payload['capabilities'] ) {
unset( $payload['capabilities'] );
}
// Add the nonce in the end, to maintain backwards compatibility of filters.
$payload['partner_config_override']['return_url'] = add_query_arg(
array( 'ppcpToken' => $onboarding_token ),
$payload['partner_config_override']['return_url']
);
return $payload;
}
}