电商支付-Paypal普通支付对接基于Restful-api-v1.Net(二)

前言跨境电商行业中,支付环节相信大家都不陌生,对接的国外支付平台可能很多,但是PayPal作为全球最重要的支付方式之一,支付转化率也有保证,一直深受各跨境电商平台青睐,本章将继续介绍PayPal对接示例实战,本次讲解是针对PayPal官方文档Payments支付流程介绍,基于.Net代码示例PayPal参考文档名词解释同步回调:及时处理支付状态的处理流程异步回调:异步处理支付状态的处理流程(支付状态最终以异步回传为准)配置准备工作登录PayPal沙盒开发者中心,endpoint:
摘要由CSDN通过智能技术生成

前言

跨境电商行业中,支付环节相信大家都不陌生,对接的国外支付平台可能很多,但是PayPal作为全球最重要的支付方式之一,支付转化率也有保证,一直深受各跨境电商平台青睐,本章将继续介绍PayPal对接示例实战,
本次讲解是针对PayPal官方文档Payments支付流程介绍,基于.Net代码示例
PayPal参考文档

名词解释

  1. 同步回调:及时处理支付状态的处理流程
  2. 异步回调:异步处理支付状态的处理流程(支付状态最终以异步回传为准)

配置准备工作

登录PayPal沙盒开发者中心
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

endpoint:paypal api地址
mode:沙盒/生产
connectionTimeout: 超时时间
requestRetries:重试次数
clientId:客户端ID
clientSecret:私钥(不要泄漏)
webhook.id:回调ID

配置文件配置如下

 <configSections>
    <section name="paypal" type="PayPal.Manager.SDKConfigHandler, PayPalCoreSDK" />
  </configSections>
  <paypal>
    <settings>
      <add name="endpoint" value="https://api.sandbox.paypal.com/" />
      <add name="oauth.EndPoint" value="https://api.sandbox.paypal.com/" />
      <add name="mode" value="sandbox" />
      <add name="connectionTimeout" value="360000" />
      <add name="requestRetries" value="1" />
      <add name="clientId" value="「clientId」" />
      <add name="clientSecret" value="「clientSecret」" />
      <add name="webhook.id" value="「webhook.id」" />
    </settings>
  </paypal>

请求授权获取Token

定义PaypalUtils工具类

        static PaypalUtils()
        {
   
            var config = GetConfig();
            ClientId = config["clientId"];
            ClientSecret = config["clientSecret"];
            Endpoint = config["endpoint"];
            WebhookId = config["webhook.id"];
        }
        // Create the configuration map that contains mode and other optional configuration details.
        public static Dictionary<string, string> GetConfig()
        {
   
            var result = ConfigManager.Instance.GetProperties();
            result["clientId"] = result["clientId"];
            result["clientSecret"] = result["clientSecret"];
            result["webhook.id"] = result["webhook.id"];
            return result;
        }
        // Create accessToken
        public static string GetAccessToken()
        {
   
            // ###AccessToken
            // Retrieve the access token from
            // OAuthTokenCredential by passing in
            // ClientID and ClientSecret
            // It is not mandatory to generate Access Token on a per call basis.
            // Typically the access token can be generated once and
            // reused within the expiry window 
            var accessToken = string.Empty;
            try
            {
   
                ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
                ServicePointManager.DefaultConnectionLimit = 9999
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值