Created
April 17, 2012 08:05
-
-
Save xcommerce-gists/2404378 to your computer and use it in GitHub Desktop.
Single Payment with PayPal Express Checkout API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_once('services/PayPalApi/PayPalAPIInterfaceServiceService.php'); | |
/* setup payment details */ | |
orderTotal = new BasicAmountType( '-your-currency-code-', '-your-amount-'); | |
$PaymentDetails= new PaymentDetailsType(); | |
$PaymentDetails->OrderTotal = $orderTotal; | |
/* create DoExpressCheckout request details */ | |
$DoECRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType(); | |
$DoECRequestDetails->PayerID = '-payer-id-from-get-EC-call; | |
$DoECRequestDetails->Token = '-token-from-set-EC-call-'; | |
$DoECRequestDetails->PaymentDetails[0] = $PaymentDetails; | |
/* create DoExpressCheckoutPayment Request */ | |
$DoECRequest = new DoExpressCheckoutPaymentRequestType(); | |
$DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails; | |
$DoECRequest->Version = '85.0'; | |
$DoECReq = new DoExpressCheckoutPaymentReq(); | |
$DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest; | |
/* Execute the API call */ | |
$paypalService = new PayPalAPIInterfaceServiceService(); | |
$DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq); | |
/* check the return status */ | |
if($DoECResponse->Ack =='Success') | |
{ | |
/* verify your payment info - before providing the item/resource to the consumer */ | |
$paymentStatus = $DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo->PaymentStatus; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_once('services/PayPalApi/PayPalAPIInterfaceServiceService.php'); | |
/* Create GetExpressCheckoutDetails request with token*/ | |
$getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType('-token-from-setEC-call-'); | |
$getExpressCheckoutDetailsRequest->Version = 85.0; | |
$getExpressCheckoutReq = new GetExpressCheckoutDetailsReq(); | |
$getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest; | |
/* execute the GetExpressCheckoutDetails API call */ | |
$paypalService = new PayPalAPIInterfaceServiceService(); | |
$getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq); | |
/* obtain the payerId */ | |
if($getECResponse->Ack =='Success') | |
{ | |
$payerId = $getECResponse->GetExpressCheckoutDetailsResponseDetails->PayerInfo->PayerID; | |
$amount = $getECResponse->GetExpressCheckoutDetailsResponseDetails->PaymentDetails->OrderTotal->value; | |
/* TODO: Make sure amount and other information matches what you've asked for */ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_once('services/PayPalApi/PayPalAPIInterfaceServiceService.php'); | |
/* Setup Payment Details */ | |
$PaymentDetails= new PaymentDetailsType(); | |
$PaymentDetails->OrderTotal = new BasicAmountType('-your-currency-code-', '-your-amount-'); | |
$PaymentDetails->PaymentAction = 'Sale'; | |
$PaymentDetails->OrderDescription = '-your-payment-order-description-'; | |
/* Setup Checkout request details */ | |
$setECReqDetails = new SetExpressCheckoutRequestDetailsType(); | |
$setECReqDetails->PaymentDetails = $PaymentDetails; | |
$setECReqDetails->CancelURL = 'http://-your-site-/-cancel-url-'; | |
$setECReqDetails->ReturnURL = 'http://-your-site-/-return-url-'; | |
/* create the SetExpressCheckoutRequest */ | |
$setECReqType = new SetExpressCheckoutRequestType(); | |
$setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails; | |
$setECReqType->Version = '85.0'; | |
$setECReq = new SetExpressCheckoutReq(); | |
$setECReq->SetExpressCheckoutRequest = $setECReqType; | |
/* execute the API call */ | |
$paypalService = new PayPalAPIInterfaceServiceService(); | |
$setECResponse = $paypalService->SetExpressCheckout($setECReq); | |
/* check the return status */ | |
if($setECResponse->Ack =='Success') | |
{ | |
$token = $setECResponse->Token; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment