-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPaymentsStandard.php
More file actions
76 lines (67 loc) · 2.03 KB
/
Copy pathPaymentsStandard.php
File metadata and controls
76 lines (67 loc) · 2.03 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
<?php
namespace Drupal\commerce_paypal\Plugin\Commerce\PaymentGateway;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OffsitePaymentGatewayBase;
/**
* Provides the Onsite payment gateway.
*
* @CommercePaymentGateway(
* id = "paypal_payments_standard",
* label = "PayPal Standard",
* display_label = "PayPal",
* forms = {
* "offsite-payment" = "Drupal\commerce_paypal\PluginForm\PaymentsStandardPaymentForm",
* },
* payment_method_types = {"paypal"},
* )
*/
class PaymentsStandard extends OffsitePaymentGatewayBase implements PaymentsStandardInterface {
/**
* {@inheritdoc}
*/
public function getRedirectUrl() {
return 'https://www.sandbox.paypal.com/cgi-bin/webscr';
}
/**
* {@inheritdoc}
*/
public function onRedirectReturn(OrderInterface $order) {
$current_request = \Drupal::getContainer()->get('request_stack')->getCurrentRequest();
// mc_gross = 89.50
// invoice = 3-TIMESTAMP
// protection_eligibility
// item_number1
// payer_id
// tax
// payment_date
// payment_status (Pending)
// notify_version
// payer_status
// payer_email
// verify_sign
// tnx_id
// pending_reason
// payment_gross
// auth
// Create the payment.
$payment_storage = \Drupal::entityTypeManager()->getStorage('commerce_payment');
$payment = $payment_storage->create([
'state' => 'authorization',
'amount' => $order->getTotalPrice(),
// Gateway plugins cannot reach their matching config entity directly.
'payment_gateway' => $order->payment_gateway->entity->id(),
'order_id' => $order->id(),
'test' => $this->getMode() == 'test',
'remote_id' => $current_request->request->get('txn_id'),
'remote_state' => $current_request->request->get('payment_status'),
'authorized' => REQUEST_TIME,
]);
$payment->save();
}
/**
* {@inheritdoc}
*/
public function onRedirectCancel(OrderInterface $order) {
// Nothing to do.
}
}