489495df
* // Create a credit card object * // DO NOT USE THESE CARD VALUES -- substitute your own * // see the documentation in the class header. * $card = new CreditCard(array( * 'firstName' => 'Example', * 'lastName' => 'User', * 'number' => '4111111111111111', * 'expiryMonth' => '01', * 'expiryYear' => '2020', * 'cvv' => '123', * 'billingAddress1' => '1 Scrubby Creek Road', * 'billingCountry' => 'AU', * 'billingCity' => 'Scrubby Creek', * 'billingPostcode' => '4999', * 'billingState' => 'QLD', * )); * * // Do a purchase transaction on the gateway * try { * $transaction = $gateway->purchase(array( * 'amount' => '10.00', * 'currency' => 'AUD', * 'description' => 'This is a test purchase transaction.', * 'card' => $card, * )); * $response = $transaction->send(); * $data = $response->getData(); * echo "Gateway purchase response data == " . print_r($data, true) . "\n"; * * if ($response->isSuccessful()) { * echo "Purchase transaction was successful!\n"; * } * } catch (\Exception $e) { * echo "Exception caught while attempting authorize.\n"; * echo "Exception type == " . get_class($e) . "\n"; * echo "Message == " . $e->getMessage() . "\n"; * } *
* $transaction = MyClass::saveTransaction($some_data); * $txn_id = $transaction->getId(); *
* // Do a purchase transaction on the gateway * try { * $transaction = $gateway->purchase(array( * 'amount' => '10.00', * 'currency' => 'AUD', * 'description' => 'This is a test purchase transaction.', * 'returnUrl' => 'http://mysite.com/paypal/return/?txn_id=' . $txn_id, * 'cancelUrl' => 'http://mysite.com/paypal/return/?txn_id=' . $txn_id, * )); * $response = $transaction->send(); * $data = $response->getData(); * echo "Gateway purchase response data == " . print_r($data, true) . "\n"; * * if ($response->isSuccessful()) { * echo "Step 2 was successful!\n"; * } * * } catch (\Exception $e) { * echo "Exception caught while attempting purchase.\n"; * echo "Exception type == " . get_class($e) . "\n"; * echo "Message == " . $e->getMessage() . "\n"; * } *
* if ($response->isRedirect()) { * // Redirect the customer to PayPal so that they can sign in and * // authorize the payment. * echo "The transaction is a redirect"; * redirectTo($response->getRedirectUrl()); * } *
* $paymentId = $_GET['paymentId']; * $payerId = $_GET['payerId']; * * // Once the transaction has been approved, we need to complete it. * $transaction = $gateway->completePurchase(array( * 'payer_id' => $payer_id, * 'transactionReference' => $sale_id, * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * // The customer has successfully paid. * echo "Step 4 was successful!\n"; * } else { * // There was an error returned by completePurchase(). You should * // check the error code and message from PayPal, which may be something * // like "card declined", etc. * } *